G
Guest
A main menu opens 30 different forms. For each form there is a command button
with code to cancel the open event if there are no records.
I have tried to create a private sub that can be used in the code for each
command button to save typing the routine out 30 times, but it doesn’t work.
What am I doing wrong?
Here is the code:
Private Sub OpenForm()
Dim stDocName As String
Dim sSQL As String
If DCount("*", sSQL) = 0 Then
MsgBox "There is no data for this asset/item."
DoCmd.CancelEvent
Else
DoCmd.OpenForm "stDocName"
DoCmd.Close acForm, "frmAssetRegister"
End If
End Sub
- - -
Behind each button I put the following code:
This example is for command called “cmdOpenA2â€
Private Sub cmdOpenA2_Click()
Dim stDocName As String
stDocName = "frmTrack1"
Dim sSQL As String
sSQL = "qryTrack1"
Call OpenForm
End sub
- - -
with code to cancel the open event if there are no records.
I have tried to create a private sub that can be used in the code for each
command button to save typing the routine out 30 times, but it doesn’t work.
What am I doing wrong?
Here is the code:
Private Sub OpenForm()
Dim stDocName As String
Dim sSQL As String
If DCount("*", sSQL) = 0 Then
MsgBox "There is no data for this asset/item."
DoCmd.CancelEvent
Else
DoCmd.OpenForm "stDocName"
DoCmd.Close acForm, "frmAssetRegister"
End If
End Sub
- - -
Behind each button I put the following code:
This example is for command called “cmdOpenA2â€
Private Sub cmdOpenA2_Click()
Dim stDocName As String
stDocName = "frmTrack1"
Dim sSQL As String
sSQL = "qryTrack1"
Call OpenForm
End sub
- - -