Solved Make sure to fill out two text boxes before saving the record

Hisoka

New member
Local time
Today, 20:42
Joined
Sep 20, 2023
Messages
17
Hello,
I have two text boxes, one called "MobileNumber" and the other called "Requests".
What command should I type in "Before Update" Event to prevent the Access from saving the record until they are filled together?

Thank you in advance..
 
Thanks,, But it didn't work for some reason.

When I wrote this code in before update
Code:
If Len(Me.MobileNumber & Requests) = 0 Then
  MsgBox "You need to fill out SomeControl"
  Cancel = True
  Me.MobileNumber.SetFocus
End If

Then After opening the form and trying to save it without filling the text box, I get the following message

Microsoft Access cannot find the object if Len(Me.'
if 'if Len(Me' is a new macro group, make sure you have saved it and that you have typed its name correctly
 
The "some reason" is that it's not valid syntax. ;) Try

If Len(Me.MobileNumber & vbNullString) = 0 OR Len(Me.Requests & vbNullString) = 0 Then

Edit: changed AND to OR
 
Actually that should be OR instead of AND, since you want both filled in.
 
I modified it and put it before update, but the same message appeared :cry:,,
Frankly, I don't know how to use the code. Should I create a macro first for this code and then put it in before update or what?

Sorry for disturbing you
 
Can you post a copy of the database you are working with? zip format.
 
You didn't by chance put the code directly in the properties window? If so, it goes here:

 
Sorry guys, it was my mistake.
I was trying to write the code from the Zoom interface 😓,
But when i research on this topic, I noticed that the code had to be written using Code Builder...
Thank you so much, @pbaldy you are a lifesaver, and thank you @jdraw for participating..
 

Users who are viewing this thread

Back
Top Bottom