Full Version: Requiring Fields in a Form to be Populated
UtterAccess Forums > Microsoft® Access > Access Forms
am1st1
I've created a form in Access that users will update with data. There are three drop down fields in this form that must be populated with a Y or N before the user can move on to the next record. How do I implement this requirement?
I've attempted to look for this on my own but haven't had any luck.
theDBguy
One way would be to check for their values in the BeforeUpdate event of the form. For example:
If IsNull(Combo1) Then
Cancel = True
End If
Hope that helps...
am1st1
I'm sorry but I'm a little confused by your explanation. Could you show it in the form of a formula?
If ( IsNull ( [Combo40] ) , Cancel = True, End If) does not work.
theDBguy
In the design view of your form, go to the Properties window for the form. Go to the Events tab. In the Before Update event, select [Event Procedure], then click on the three dots (...) next to it. In the code window that opens up, type something like the following in between the Private Sub and End Sub lines:
If IsNull(Combo40) Then
MsgBox "Please select a value for Combo40", vbOkOnly, "Required Fields Missing"
Cancel = True
End If
Hope that helps..
am1st1
Part of this works. The msg box will appear and state i need to update a field. When I click OK the form moves to the next record. How do I get it to stay on the record that needs updating?
theDBguy
Did you have Cancel=True? Can you post the code you ended up using?
am1st1
I tried to include Cancel=True but it did not like it. Here's the code I'm currently using:
=IIf(IsNull([Combo40]),MsgBox("Please select a value for SAP Adjustment required"))
theDBguy
Hi,
id you read and follow my instructions on my 2nd post? It seems that you have the code differently than what I recommended. If you'll notice, I recommended using the If/Then else statement, but you are using the Immediate If (IIf) statement.
Hope that helps...
am1st1
I don't see an If/Then else statement -- what should I be looking for?
am1st1
Let me apologize. I didn't realize you were referring to VBA codes. I was attempting to do this in Expression Builder.
It worked.
Thanks for your help.
theDBguy
You're welcome. I know it can be confusing at times. Good luck with your project.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.