Where am I going wrong

constantG

Registered User.
Local time
Today, 14:31
Joined
Jun 24, 2009
Messages
92
I'm confused. This code works from a button on a form

Code:
Private Sub Command0_Click()
    Dim intBoatNumber As Integer
    
    intBoatNumber = Nz(DLookup("intGlobalOptionsId", "tblBoat", "accStatus = 'On'"))
    DoCmd.OpenForm "Global", acNormal, , "Forms![Global].[intGlobalId]=" & intBoatNumber, acFormEdit, acDialog
    Exit Sub
    
End Sub
So why can't I use this in a separate module that is called from the switchboard?

The form opens but always goes to a blank record. :(
 
Your code is not testing for a reasonable value in the intBoatNumber variable after the DLookup().
 
Why? Like I said, I'm confused.
 
Change the code to:
Code:
Private Sub Command0_Click()
   Dim intBoatNumber As Integer

   intBoatNumber = Nz(DLookup("intGlobalOptionsId", "tblBoat", "accStatus = 'On'"))
   [COLOR="Red"]MsgBox "IntBoatNumber is = [" & intBoatNumber & "]"[/COLOR]
   DoCmd.OpenForm "Global", [COLOR="Red"], , "[intGlobalId]=" & intBoatNumber[/COLOR], acFormEdit, acDialog
   Exit Sub

End Sub
 
That is the weirdest.

I did the above, it worked but then I took out the msgbox (the only difference between mine and yours) and it worked.

I do not understand. But thanks
 
Your original code which was opening the Global form required that the Global form already be open. I assume you had the button on the Global form.
 

Users who are viewing this thread

Back
Top Bottom