Rockape
Registered User.
- Local time
- Today, 12:18
- Joined
- Aug 24, 2007
- Messages
- 271
Hi,
grateful for advice:
1. I have the following code which is assigned to the beforeupdate event on the form.
2. I also have a button on this form which runs a macro which closes this form and saves the data.
The routine is as follows:
I populate several fields within the form. I then press the button which checks all the fields and if any field is left unpopulated then a message box highlights the missing fields. If all the fields are populated the record is saved.
My purpose:
I would like the following to happen:
If I press YES the msg box would close and I would return to the unfinished form (for editing)
If I press NO the msg box would close the form and the entries would not be saved.
However:
My problem is that when the message box pops up with the missing fields and I either press yes "I get a runtime error 2501". If i press no the routine works, i.e. the message box and the form close.
The code is :
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
Dim blnError As Boolean
Dim testmsg As Integer
If Nz(Me.add1, "") = "" Then
blnError = True
strMsg = strMsg & "Address1" & vbCrLf
End If
If Nz(Me.add2, "") = "" Then
blnError = True
strMsg = strMsg & "Address2" & vbCrLf
End If
If Nz(Me.DOB, "") = "" Then
blnError = True
strMsg = strMsg & "Date of Birth" & vbCrLf
End If
If Nz(Me.Tel_No, "") = "" Then
blnError = True
strMsg = strMsg & "Telephone Number" & vbCrLf
End If
If blnError Then
strMsg = "YOU ARE MISSING: " & vbCrLf & strMsg & vbCrLf & "Please fix them..."
testmsg = MsgBox(strMsg, vbYesNo, "Errors Exist")
End If
If testmsg = vbYes Then
DoCmd.Close
End If
If testmsg = vbNo Then
DoCmd.RunMacro ("close newholder")
End If
End Sub
Cheers
grateful for advice:
1. I have the following code which is assigned to the beforeupdate event on the form.
2. I also have a button on this form which runs a macro which closes this form and saves the data.
The routine is as follows:
I populate several fields within the form. I then press the button which checks all the fields and if any field is left unpopulated then a message box highlights the missing fields. If all the fields are populated the record is saved.
My purpose:
I would like the following to happen:
If I press YES the msg box would close and I would return to the unfinished form (for editing)
If I press NO the msg box would close the form and the entries would not be saved.
However:
My problem is that when the message box pops up with the missing fields and I either press yes "I get a runtime error 2501". If i press no the routine works, i.e. the message box and the form close.
The code is :
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
Dim blnError As Boolean
Dim testmsg As Integer
If Nz(Me.add1, "") = "" Then
blnError = True
strMsg = strMsg & "Address1" & vbCrLf
End If
If Nz(Me.add2, "") = "" Then
blnError = True
strMsg = strMsg & "Address2" & vbCrLf
End If
If Nz(Me.DOB, "") = "" Then
blnError = True
strMsg = strMsg & "Date of Birth" & vbCrLf
End If
If Nz(Me.Tel_No, "") = "" Then
blnError = True
strMsg = strMsg & "Telephone Number" & vbCrLf
End If
If blnError Then
strMsg = "YOU ARE MISSING: " & vbCrLf & strMsg & vbCrLf & "Please fix them..."
testmsg = MsgBox(strMsg, vbYesNo, "Errors Exist")
End If
If testmsg = vbYes Then
DoCmd.Close
End If
If testmsg = vbNo Then
DoCmd.RunMacro ("close newholder")
End If
End Sub
Cheers
