Hello,
I have declared a global variable in the procedure of one of my forms and wish to recall the same variable in when a different form opens. I don't know why it tells me 'variable not declared'. What is the error? Can anyone help?
Option Compare Database
Option Explicit
'declaring the public variable
Public gblnOpenedByAnother As Boolean
'on click of the command button, this happens
Private Sub Insert_Record_Before_Click()
Dim lngmRecno As Long
lngmRecno = Me.Recno
CurrentDb.Execute "insert into tblMain_Table (Recno) Values (" & lngmRecno & ")", dbFailOnError
gblnOpenedByAnother = True
DoCmd.OpenForm "Append"
'opens the second form
DoCmd.GoToRecord , , acLast
End Sub
'on opening the second form
Private Sub Form_Open(Cancel As Integer)
If gblnOpenedByAnother = False Then 'error here
DoCmd.GoToRecord , , acNewRec
End If
End Sub
I have declared a global variable in the procedure of one of my forms and wish to recall the same variable in when a different form opens. I don't know why it tells me 'variable not declared'. What is the error? Can anyone help?
Option Compare Database
Option Explicit
'declaring the public variable
Public gblnOpenedByAnother As Boolean
'on click of the command button, this happens
Private Sub Insert_Record_Before_Click()
Dim lngmRecno As Long
lngmRecno = Me.Recno
CurrentDb.Execute "insert into tblMain_Table (Recno) Values (" & lngmRecno & ")", dbFailOnError
gblnOpenedByAnother = True
DoCmd.OpenForm "Append"
'opens the second form
DoCmd.GoToRecord , , acLast
End Sub
'on opening the second form
Private Sub Form_Open(Cancel As Integer)
If gblnOpenedByAnother = False Then 'error here
DoCmd.GoToRecord , , acNewRec
End If
End Sub