want to check the values of my controls in the code behind the Submit button

sree0009

Registered User.
Local time
Yesterday, 18:03
Joined
Nov 20, 2017
Messages
15
hi i have stuck in the forms update event where the event is not firing up.
i have to check or validate certain feilds and have to make sure they are not empty in the fields. example i have 8 fields.

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull(Form_Master.Primary_Key) = True Then
Me!Primary_Key.SetFocus
Cancel = True
Exit Sub
ElseIf IsNull(Form_Master.AddSuffix) = True Then
Me!AddSuffix.SetFocus
Cancel = True
Exit Sub
ElseIf CppValue.ListIndex = -1 Then
Me!CppValue.SetFocus
Cancel = True
Exit Sub
 
Last edited:
If the controls could hold a zero length string, try this test instead:

If Len(Me.Primary_Key & vbNullString) = 0 Then

Also, you're aware that the update events won't fire if nothing was changed (updated)?
 
hi, Actually my main reason was the same issue you stated before. my form has many fields and if the user tries to press save button it saves the record. so it skips the validation written in the before update events. i tried with after update still no luck.
why is it that user has to press on certain textbox or combo box to get fire the event ?
 
Theoretically if they have changed anything, there's nothing to save (update). Also, the form has to be bound to a table/query for the update events to fire. Is yours, or are you saving with code?
 
sorry i didnt get you. but here is exactly
what's happening.

when i open the master form it has 35 fields where i require few fields to get validated as 8 of them. but if i dont press on any textboxes and just press on save button still my records saves as null values in the table. yes my form is bounded to Master table and Master is my forms name.

Whats expected
when i open the form and just press on save button it should check for the necessary fields and remain the cursor on that specific textbox and remain untill all fields are filled then should save.

Somewhere in the bottom of my forms update event i used this one to restrict the data to auto save
ElseIf Not blnSave Then
Cancel = True
Me.Undo
End If
 
Have you considered making certain fields required in the table, so that Access won't allow a record to be saved if they're left Null? That's what I would do; the code in the before update event gives you a more user-friendly error and more control over what happens.
 
hi Pat, can you be more detail. i cant get you what you meant about response ? Also i said before my formsbefore update event is not firing all the cases of condition
 
I'll get out of the way.
 
im sorry for editing the original post. yes i kept stop in the code but couldnt figure out still. unfotunately i swapped the code into my save button and changed a bit now its working. thanks pat.
 

Users who are viewing this thread

Back
Top Bottom