UtterAccess.com
Thank you for your support!       Follow UtterAccess on Twitter
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Compile Error - Invalid Outside Procedure Problem, Office 2003    
 
   
catbeasy
post Mar 31 2010, 03:26 PM
Post #1

UtterAccess Veteran
Posts: 350



I put the below code in my code window, but am getting an error that refers to the assigning the: objrun1 variable. The error says: Compile Error; Invalid Outside Procedure

I have other variables to add and would like to place them all at the top at the public level. Can anyone tell me what I'm doing wrong?

Thanks..

Option Explicit
Option Compare Database

Public objrun1 As String
objrun1 = "qry_Mbr_Grpd"

Public Function fcn_Run_Rpt_PT1()
DoCmd.OpenQuery objrun1
End Function
Go to the top of the page
 
+
Bob_L
post Mar 31 2010, 03:32 PM
Post #2

Utterly Banned
Posts: 7,038



This part:

objrun1 = "qry_Mbr_Grpd"


can't be outside a function (or sub) unless you do this:

Public Const objrun1 As String = "qry_Mbr_Grpd"
Go to the top of the page
 
+
Ken Hoskins
post Mar 31 2010, 03:34 PM
Post #3

New Member
Posts: 1
From: Simpsonville, SC



QUOTE (catbeasy @ Mar 31 2010, 04:26 PM) *
I put the below code in my code window, but am getting an error that refers to the assigning the: objrun1 variable. The error says: Compile Error; Invalid Outside Procedure

I have other variables to add and would like to place them all at the top at the public level. Can anyone tell me what I'm doing wrong?

Thanks..

Option Explicit
Option Compare Database

Public objrun1 As String
objrun1 = "qry_Mbr_Grpd"

Public Function fcn_Run_Rpt_PT1()
DoCmd.OpenQuery objrun1
End Function



objrun1 = "qry_Mbr_Grpd"

The above line can not appear outside of a function.


Public Function fcn_Run_Rpt_PT1()
objrun1 = "qry_Mbr_Grpd"
DoCmd.OpenQuery objrun1
End Function


Go to the top of the page
 
+
catbeasy
post Mar 31 2010, 04:05 PM
Post #4

UtterAccess Veteran
Posts: 350



QUOTE (boblarson @ Mar 31 2010, 09:32 PM) *
This part:

objrun1 = "qry_Mbr_Grpd"


can't be outside a function (or sub) unless you do this:

Public Const objrun1 As String = "qry_Mbr_Grpd"

ok, cool, that worked..

so I modified the code a bit to include calling a function. Is there a way to assign the function I'm calling to a variable? I tried to do it like the below, but it would not allow me, telling me "Expected Procedure, not variable."

Presumably, this is because I've assigned the function to a string variable and when calling functions directly from code, I don't enclose in quotes..

I guess I'm wanting to know how I declare a variable when wanting to Call that variable from code?

=========================================
Public Const objrun1 As String = "Check_Mbr_Cov_Gap"
Public Const objrun2 As String = "qry_Mbr_Grpd"

Public Function fcn_Run_Rpt_PT1()

Call objrun1
DoCmd.OpenQuery objrun2
End Function
Go to the top of the page
 
+
Bob_L
post Mar 31 2010, 04:08 PM
Post #5

Utterly Banned
Posts: 7,038



Try

Eval(objrun1 & "()")
Go to the top of the page
 
+
catbeasy
post Mar 31 2010, 06:08 PM
Post #6

UtterAccess Veteran
Posts: 350



QUOTE (boblarson @ Mar 31 2010, 10:08 PM) *
Try

Eval(objrun1 & "()")

ok, that worked.

now got another issue..want one of the fields to be populated with those variables. So using a 'For i = ' statement, it is supposed to iterate thru and populate the variable definition of objrun which is in a different module (I posted the declarations in that module below the main code). What it does do is populate the 4 records with 1, 2, 3, 4. It doesn't populate it with the definition of the variables, just the i variable..(I've highlighted the part that doesn't work right in the main code)..

What I want it to populate each record with is the definition of the variable that's run as:

OBJ_RUN
fcn_Check_Mbr_Cov_Gap
qry_Mbr_Grpd
qry_updte_Mbr_Grp_EFF_DT
qry_delte_Mbr_Nvr_EFF

Thanks for any continued assistance..

=========================================

Public Function fcn_updates()

Dim i As Integer
Dim d As DAO.Database
Dim r As Recordset
Dim strSQL As String
Dim strObjTbl As String
Dim strSQLAppnd As String
Dim strSQLDelete As String
Dim strObjRun1 As String


strTbl = "tbl_RptTracker"
strSQL = "select * from " & strTbl

Set d = CurrentDb
Set r = d.OpenRecordset(strSQL, dbOpenDynaset)

For i = 1 To 4

r.AddNew
r!ST = Now()
r!OBJ_RUN = objrun & Trim(i)
r.Update

Call Eval(fcn_Run_Rpt_PT & Trim(Str(i)))

r.MoveLast
r.Edit
r!ET = Now()
r.Update

Next i


End Function

========================

delarations in other module:

Public Const objrun1 As String = "fcn_Check_Mbr_Cov_Gap"
Public Const objrun2 As String = "qry_Mbr_Grpd"
Public Const objrun3 As String = "qry_updte_Mbr_Grp_EFF_DT"
Public Const objrun4 As String = "qry_delte_Mbr_Nvr_EFF"

This post has been edited by catbeasy: Mar 31 2010, 06:09 PM
Go to the top of the page
 
+

Reply to this topicStart new topic

 



RSS Go to Top  ·  Lo-Fi Version Time is now: 16th May 2012 - 06:54 PM

Tag cloud: