Compile Error in OnOpen (1 Viewer)

quest4

Registered User.
Local time
Today, 01:09
Joined
Oct 12, 2004
Messages
246
Good afternoon, I have a form and in the OnOpen I have a procedure which I have used several times in the past, so I tried to modify this form and suddenly I am getting a Not Defined Compile Error with Response hi-lited. Here is the code:
Private Sub Form_Open(Cancel As Integer)
Dim myMemberNo As String
Response = MsgBox("Would You Like to Issue a New Member.", vbYesNo + vbDefaultButton2, "New?")
If Response = vbYes Then
DoCmd.GoToRecord , , acNewRec
Forms!frmAddresses!FirstName.SetFocus
DoCmd.Maximize
ElseIf Response = vbNo Then
myMemberNo = InputBox(Prompt:="What is the Member No?")
If myMemberNo = Empty Then
MsgBox Prompt:="You Did NOT Enter a Member No."
DoCmd.Close
Else
Me.RecordsetClone.FindFirst "[AddressID] = '" & myMemberNo & "'"
If Me.RecordsetClone.NoMatch Then
MsgBox "Couldn't Find Member No." & myMemberNo
DoCmd.Close
Else
Me.Bookmark = Me.RecordsetClone.Bookmark
DoCmd.Maximize
End If
End If
End If
End Sub
I have used this successfully in a half dozen other forms, but I can not see what is wrong here, any suggestions? Thank you in advance for any assistance.:confused::eek:
 

missinglinq

AWF VIP
Local time
Today, 01:09
Joined
Jun 20, 2003
Messages
6,420
The first thing I would do is to move this code into the Form_Load event, rather than having it in the Form_Open event. The truth is that very few things can be successfully executed from Form_Open. See if this makes a difference.
 

quest4

Registered User.
Local time
Today, 01:09
Joined
Oct 12, 2004
Messages
246
Thank you for the response. Same thing, Compile Error, "Variable Not Defined". I have used this several times and no problems, even in the OnOpen, where it has worked very well, till now. For some reason, it suddenly does not know what response is. Oh I did check to make sure the same references were checked on and they are. Any thoughts or suggestions?
 

MSAccessRookie

AWF VIP
Local time
Today, 01:09
Joined
May 2, 2008
Messages
3,428
Thank you for the response. Same thing, Compile Error, "Variable Not Defined". I have used this several times and no problems, even in the OnOpen, where it has worked very well, till now. For some reason, it suddenly does not know what response is. Oh I did check to make sure the same references were checked on and they are. Any thoughts or suggestions?



My code does this when the "Option Explicit" is set in the program. Perhaps this has been done. I did notice the lack of DIM statements, but I am not enough of a VBA expert to comment as to whether that was the cause. Look for an "Option Explicit" statement. If you find one then you can:
  1. Get rid of it (not usually a good idea) OR
  2. Define the variables that are used in the code (Usually a better idea)
 

quest4

Registered User.
Local time
Today, 01:09
Joined
Oct 12, 2004
Messages
246
thanks again for the response. I tried to dim response and that worked, but I should not of had to because it is a VB known variable and I have not had to do that in the other dbases where this was used.
 

MSAccessRookie

AWF VIP
Local time
Today, 01:09
Joined
May 2, 2008
Messages
3,428
thanks again for the response. I tried to dim response and that worked, but I should not of had to because it is a VB known variable and I have not had to do that in the other dbases where this was used.


I am glad to help, but as I pointed out, I am not a VB Expert. I just know what looks different, and recognized the error as one that I had encountered before. Perhaps one of the FORUM VB Experts can comment on this to enlighten us both.:)
 

dkinley

Access Hack by Choice
Local time
Today, 00:09
Joined
Jul 29, 2008
Messages
2,016
For integer based responses such as this I've always had to declare the variable before initialization.

Will be the first for me about Access 'knowing' about variables without them having to be declared. The only thing I am aware about Access 'knowing' are functions.

Nice 'stare-and-compare' MSAccessRookie.

-dK
 

Users who are viewing this thread

Top Bottom