I am using the Macro and Code below to open a form. I have a problem when Zero records are returned....I get a macro error.
This code is attached to the Form open event...it checks for zero records returned.
*********************************************************
Option Compare Database
Private Sub Form_Open(Cancel As Integer)
Dim strRecError
If Me.RecordSource <> "" Then
If Me.Recordset.RecordCount = 0 Then
strRecError = "No Records. "
End If
Else
strRecError = "No recordset. "
End If
If strRecError <> "" Then
If MsgBox(strRecError & "Continue?", vbYesNo) = vbNo Then
Cancel = True
End
End If
End If
End Sub
*********************************************************
But at the same time I am running this Macro. I am showing it converted to a Function for this explaination..
***********************************************************
Option Compare Database
'----------------------------------------------------------
' Test_ActionNew
'
'----------------------------------------------------------
Function Test_ActionNew()
On Error GoTo Test_ActionNew_Err
DoCmd.OpenForm "Employee Frm", acNormal, "Employee Action Item Filter Qry", "", acEdit, acNormal
Forms![Employee Frm]!Unlock.Visible = True
Forms![Employee Frm]![Unlock Btn].Visible = True
Test_ActionNew_Exit:
Exit Function
Test_ActionNew_Err:
MsgBox Error$
Resume Test_ActionNew_Exit
End Function
***********************************************************I would like to combine these two sets of code into a Function that checks for Zeror records and returns message box as the upper code does. When the message box shows the "Yes" button works fine. But when I selct the "No" button errors the macro (bottom code) when it tries perform the two set value items. Can someone help me combine these two sets of code into one Function? Of course, I would delete the macro at that time and rely on the code. This code/Function will be called from a Swichboard.
Thanks,
This code is attached to the Form open event...it checks for zero records returned.
*********************************************************
Option Compare Database
Private Sub Form_Open(Cancel As Integer)
Dim strRecError
If Me.RecordSource <> "" Then
If Me.Recordset.RecordCount = 0 Then
strRecError = "No Records. "
End If
Else
strRecError = "No recordset. "
End If
If strRecError <> "" Then
If MsgBox(strRecError & "Continue?", vbYesNo) = vbNo Then
Cancel = True
End
End If
End If
End Sub
*********************************************************
But at the same time I am running this Macro. I am showing it converted to a Function for this explaination..
***********************************************************
Option Compare Database
'----------------------------------------------------------
' Test_ActionNew
'
'----------------------------------------------------------
Function Test_ActionNew()
On Error GoTo Test_ActionNew_Err
DoCmd.OpenForm "Employee Frm", acNormal, "Employee Action Item Filter Qry", "", acEdit, acNormal
Forms![Employee Frm]!Unlock.Visible = True
Forms![Employee Frm]![Unlock Btn].Visible = True
Test_ActionNew_Exit:
Exit Function
Test_ActionNew_Err:
MsgBox Error$
Resume Test_ActionNew_Exit
End Function
***********************************************************I would like to combine these two sets of code into a Function that checks for Zeror records and returns message box as the upper code does. When the message box shows the "Yes" button works fine. But when I selct the "No" button errors the macro (bottom code) when it tries perform the two set value items. Can someone help me combine these two sets of code into one Function? Of course, I would delete the macro at that time and rely on the code. This code/Function will be called from a Swichboard.
Thanks,