Richard1980
Registered User.
- Local time
- Today, 19:22
- Joined
- Aug 13, 2012
- Messages
- 72
Hello gents,
I am struggling since yesterday on this item. I have a Form_BeforeUpdate event to run some (several) checks in my form. This is a bound form to a table and it has these properties set:
- Cycle: current record;
- Data entry: yes.
In the form there is a button to save current record and move ahead to another (blank) record.
Code for the Form_BeforeUpdate event is the following:
Save button has a cmdSave_click event:
When I click on the cmdSave button the BeforeUpdate event doesn't work as expected. A MsgBox comes up twice (The following field .... is mandatory), I press OK on the MsgBox and the procedure try to run the DoCmd.RunCommand acCmdSaveRecord given an error: "Property not found". Debugging shows me the row where DoCmd.RunCommand stands.
How to get running the BeforeUpdate correctly and, if all checks are confirmed, saving the records as wanted?
Thanks for your help.
Bye.
Riccardo
I am struggling since yesterday on this item. I have a Form_BeforeUpdate event to run some (several) checks in my form. This is a bound form to a table and it has these properties set:
- Cycle: current record;
- Data entry: yes.
In the form there is a button to save current record and move ahead to another (blank) record.
Code for the Form_BeforeUpdate event is the following:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
'### check if mandatory fields are blank/null ###'
Dim ctl As Control
Dim testo As String
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
If ctl.Tag = "Required" And IsNull(ctl) Then
testo = ctl.Controls(0).Caption
testo = Left(testo, Len(testo) - 1)
MsgBox "The following field is required: " & vbCrLf & vbCrLf _
& "- " & testo
Cancel = True
ctl.SetFocus
Exit Sub
End If
End Select
Next ctl
'### Check lenght of Latitude field ###'
If Len(txtLat) <> 7 Then
MsgBox "Latitude is not correct, please complete all components of the field."
Cancel = True
txtLat.SetFocus
Exit Sub
ElseIf IsNull(txtLat) Then
Dim textMessage As Integer
textMessage = MsgBox("Latitude data is not mandatory, but the distance calculation feature in the " _
& "flight data center will not be available. Do you want to add latitude?", vbYesNo)
If textMessage = vbYes Then
txtLat.SetFocus
Exit Sub
Else
End If
Else
txtLat = UCase(txtLat)
End If
'### Check lenght of Longitude field ###'
If Len(txtLon) <> 8 Then
MsgBox "Longitude is not correct, please complete all components of the field."
Cancel = True
txtLon.SetFocus
Exit Sub
ElseIf IsNull(txtLon) Then
Dim textMessage2 As Integer
textMessage2 = MsgBox("Longitude data is not mandatory, but the distance calculation feature in the " _
& "flight data center will not be available. Do you want to add longitude?", vbYesNo)
If textMessage2 = vbYes Then
txtLon.SetFocus
Exit Sub
Else
MsgBox "All data you inserted will be saved shortly."
End If
Else
txtLon = UCase(txtLon)
End If
'### checks for the Latitude field components ###'
If Mid(txtLat, 2, 2) >= 90 Then
MsgBox "Latitude cannot be higher than 90° degrees, please edit the field accordingly"
Cancel = True
txtLat.SetFocus
ElseIf Mid(txtLat, 4, 2) >= 60 Then
MsgBox "Minutes of Latitude field cannot be higher than 60, please edit the field accordingly"
Cancel = True
txtLat.SetFocus
ElseIf Mid(txtLat, 6, 2) >= 60 Then
MsgBox "Seconds of Latitude field cannot be higher than 60, please edit the field accordingly"
Cancel = True
txtLat.SetFocus
Else
txtLat = UCase(txtLat)
End If
'### checks for the Longitude field components ###'
If Mid(txtLon, 2, 3) >= 180 Then
MsgBox "Longitude cannot be higher than 180° degrees, please edit the field accordingly"
Cancel = True
txtLon.SetFocus
Exit Sub
ElseIf Mid(txtLon, 5, 2) >= 60 Then
MsgBox "Minutes of Longitude field cannot be higher than 60, please edit the field accordingly"
Cancel = True
txtLon.SetFocus
ElseIf Mid(txtLon, 7, 2) >= 60 Then
MsgBox "Seconds of Longitude field cannot be higher than 60, please edit the field accordingly"
Cancel = True
txtLon.SetFocus
Else
txtLon = UCase(txtLon)
End If
End Sub
Save button has a cmdSave_click event:
Code:
Private Sub cmdSave_Click()
Call Form_BeforeUpdate(False)
DoCmd.RunCommand acCmdSaveRecord
DoCmd.GoToRecord , , acNewRec
End Sub
When I click on the cmdSave button the BeforeUpdate event doesn't work as expected. A MsgBox comes up twice (The following field .... is mandatory), I press OK on the MsgBox and the procedure try to run the DoCmd.RunCommand acCmdSaveRecord given an error: "Property not found". Debugging shows me the row where DoCmd.RunCommand stands.
How to get running the BeforeUpdate correctly and, if all checks are confirmed, saving the records as wanted?
Thanks for your help.
Bye.
Riccardo