Function not returning value

  • Thread starter Thread starter Mark A. Sam
  • Start date Start date
M

Mark A. Sam

In the following function:

Public Function SetPubOrdJob()

SetPubOrdJob = pubOrdJob


End Function


pubOrdJob is a public variable (long integer). When pubOrdJob has a value,
the function delivers 0. Stepping through the funtion when pubOrdJob has a
value of 107734, the function delivered 0 when the break was on the End
Function line.

From the immediate window:

?pubOrdJob
107734

?SetPubOrdJob()
0

I am using Access2002 on an Access 2000 DB and Windows XP. This issue
doesn't exist on a Client machine running the same configuration.

Any ideas on why this is happening would be appreciated.

God Bless,

Mark A. Sam
 
Mark A. Sam said:
In the following function:

Public Function SetPubOrdJob()

SetPubOrdJob = pubOrdJob


End Function


pubOrdJob is a public variable (long integer). When pubOrdJob has a value,
the function delivers 0. Stepping through the funtion when pubOrdJob has a
value of 107734, the function delivered 0 when the break was on the End
Function line.

Try ...

Public Function SetPubOrdJob() as Long
etc..
 
Mark:

Are both the variable and function declared in a standard module (global module,
not behind a form or report)? When I test your scenario with all placed in a
standard module, everything seems to work okay.

Immediate window:

? pubOrdJob
107734
? SetPubOrdJob()
107734
 
Bruce,

Yes, the variable and the function are in a standard module. Here is
another observation that I made. In the immediate window I assigned a value
for pubOrdJob which the Fucntion delivered.

pubordjob = 123

?setpubordjob()
123


Just for the heck of it, here is the procedure that assigns the value for
pubOrdJob. The function feeds criteria for the queries that are run within
the proecedure.




Private Sub Import_Click()
On Error GoTo error_Section

DoCmd.OpenForm "Action Message", , , , , , "Importing"
Me.Repaint


Dim strSQL As Variant
Dim varItem As Variant
Dim ctl As Control
Set ctl = [ImportList]

DoCmd.SetWarnings False
For Each varItem In ctl.ItemsSelected
pubOrdJob = ctl.ItemData(varItem)

'Import Order Entry Header Data
DoCmd.OpenQuery ("SQLImport Order Entry Header")

'Import Products
DoCmd.OpenQuery ("SQLImport Order Entry ST Products")

'Import Products Shipped
DoCmd.OpenQuery ("SQLImport Order Entry ST Products Shipped")

'Import Materials
DoCmd.OpenQuery ("SQLImport Order Entry St Materials")

'Import Tasks
DoCmd.OpenQuery ("SQLImport Order Entry St Tasks")

'Import Subcontract Services
DoCmd.OpenQuery ("SQLImport Order Entry St Subcontract Services")


'Import Technical Specs
DoCmd.OpenQuery ("SQLImport Order Entry Technical Specs")

'Import Hold Status Notes
DoCmd.OpenQuery ("SQLImport Order Entry Hold Status Notes")

'Import Customer Notes

DoCmd.OpenQuery ("SQLImport Order Entry Customer Notes")

'Import Counterplate Specs
DoCmd.OpenQuery ("SQLImport Order Count")

'Import Rules SPecs w Cp
DoCmd.OpenQuery ("SQLImport Order Ruleht w/ CP ST")

'Import Rule St Specs w/o CP

DoCmd.OpenQuery ("SQLImport Order Ruleht w/o CP ST")

'Import Shipping

DoCmd.OpenQuery ("SQLImport Shipping")

Next varItem



exit_Section:
DoCmd.SetWarnings True
If IsLoaded("Order Entry Header Admin") Then
DoCmd.Close acForm, "Order Entry Header Admin"
DoCmd.OpenForm "Order Entry Header Admin"
End If
On Error Resume Next
DoCmd.Close acForm, "Action Message"
[ImportList].Requery
MsgBox "Order Imported Successfully"
Exit Sub

error_Section:
DoCmd.SetWarnings True
MsgBox Err.Description
Resume exit_Section
'Stop
Resume Next



End Sub
 
Suddenly it works.

I changed the line

Dim varItem As Variant

to

Dim varItem As Long


Then I received an error and changed it back. Now it is working. I copied
an pasted the code from one form module to another. Possible there was some
corruption?

God Bless,

Mark
 
Suddenly it works.
I changed the line

Dim varItem As Variant

to

Dim varItem As Long


Then I received an error and changed it back. Now it is working. I copied
an pasted the code from one form module to another. Possible there was some
corruption?

Possibly, and if so it would likely be corruption in the VBA. There is a
"decompile" switch (available in Access 97, 2000 and, apparently, 2002) that can
be used to help correct this situation, but this is more of a "last resort" in
that there is some risk to the file as described in
http://www.trigeminal.com/usenet/usenet004.asp?1033 (so ... work with a copy of
the file). Further information is available at
http://www.databasecreations.com/largedb.htm. The procedure I use when
implementing this is as follows:

1) BACK UP YOUR MDB FILE!
1) BACK UP YOUR MDB FILE! (I meant it the first time <g>)
2) Compact the MDB.
3) Implement the "/decompile" as described in the articles I referenced.
(Access 2000, and later, don't provide the confirmation dialog that
existed in Access 97, but the decompile will still take place.)
4) Open Access normally and compact the MDB again to clean up.
5) Compile and save.
6) Compact again before testing/using.
 
Back
Top