Shaldaman wrote:
There's a couple of buttons on the form that trigger different events.
"button1" adds records into a table, "button2" opens a new form based
on the newly entered record. If a user clicks on button2 before button1
has already been clicked, the new form will open with blank fields
since no data has been entered into the table. If you can think of a
better way of doing it, please let me know..Thanks
Osmethod has suggested one viable way of doing this that is form level.
I'd prefer to do this the following way.
In the second form, the one that opens, in the on open event put in the
following code, near the top of your code, if you already have code
there for the on open event (watch for wrap):
Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.EOF Then
msgbox "You haven't added any records yet!", vbexclamation, "You Need
to Click Button1, first!"
Cancel = True
end if
End Sub
If you already have other code, do it this way:
Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.EOF Then
msgbox "You haven't added any records yet!", vbexclamation, "You Need
to Click Button1, first!"
Cancel = True
else
<do other code>
end if
End Sub
That's not all, just the above will raise an error with button2 if
button2 does not have error trapping.
Button2 should look something like:
Private Sub Button2_Click()
On Error GoTo Err_Proc
DoCmd.OpenForm "The FormThatOpensTheTableName"
Exit_Proc:
Exit Sub
Err_Proc:
Select case err.number
Case 2501 'DoCmd cancelled - form had no records
Resume Exit_Proc
Case Else
MsgBox "Error " & Err.Number & " " & Err.Description,
vbCritical, "Error Button2_Click", Err.HelpFile, Err.HelpContext
Resume Exit_Proc
End Select
End Sub
--
Tim
http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me