Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Form Function

Status
Not open for further replies.

puforee

Technical User
Oct 6, 2006
741
US
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,




 
End
Why this instruction ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV....please ignore the End. It was left over form something else and I forgot to delete it in this thread.

Thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top