accvbalearner
Registered User.
- Local time
- Yesterday, 23:53
- Joined
- Jan 3, 2013
- Messages
- 42
Hello, first time posting with the site, so I hope I get this right.
I am building a form for entering data into a single table. I referred to another user's VBA code to check for multiple blank fields in the form by using the Other Tag property for the fields I want populated and then set the focus back to the first field in the form if there were any blanks.
The idea is to require the user entering data to enter data into these required fields. The code works, mostly, because it stops the record from being entered the first time thorugh. The problemm is that if the user tabs through or clicks the arrow to move to a new record on the form without changing or adding any data the second time, when the ok is clicked it adds the record to the table with the fields that I want populated as blank. I am using the following code on the Forms BeforeUpdate Event.
I would like to use this generalized code so that I can easily incorporate it into other forms that I will be designing in this same database.
Thanks in advance for any help you can offer!
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctr As Control
Dim strMsg As String
'Loop through every control on the form
For Each ctr In Me.Controls
'Look for a Particular Tag
If ctr.Tag = "BlkChk" Then
'Create a List of empty questions
If IsNull(ctr) Then
strMsg = strMsg & "_ " & ctr.Name & vbCrLf
End If
End If
Next ctr
'Did We Find Any Unanswered Questions?
If strMsg <> "" Then
If vbOK = MsgBox("The following fields require a response" & vbCrLf & vbCrLf & _
strMsg & vbCrLf & vbCrLf & "Do you want to proceed?", _
vbOKOnly) Then
Me.Work_Order__.SetFocus
End If
End If
End Sub
I am building a form for entering data into a single table. I referred to another user's VBA code to check for multiple blank fields in the form by using the Other Tag property for the fields I want populated and then set the focus back to the first field in the form if there were any blanks.
The idea is to require the user entering data to enter data into these required fields. The code works, mostly, because it stops the record from being entered the first time thorugh. The problemm is that if the user tabs through or clicks the arrow to move to a new record on the form without changing or adding any data the second time, when the ok is clicked it adds the record to the table with the fields that I want populated as blank. I am using the following code on the Forms BeforeUpdate Event.
I would like to use this generalized code so that I can easily incorporate it into other forms that I will be designing in this same database.
Thanks in advance for any help you can offer!
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctr As Control
Dim strMsg As String
'Loop through every control on the form
For Each ctr In Me.Controls
'Look for a Particular Tag
If ctr.Tag = "BlkChk" Then
'Create a List of empty questions
If IsNull(ctr) Then
strMsg = strMsg & "_ " & ctr.Name & vbCrLf
End If
End If
Next ctr
'Did We Find Any Unanswered Questions?
If strMsg <> "" Then
If vbOK = MsgBox("The following fields require a response" & vbCrLf & vbCrLf & _
strMsg & vbCrLf & vbCrLf & "Do you want to proceed?", _
vbOKOnly) Then
Me.Work_Order__.SetFocus
End If
End If
End Sub