BeforeUpdate required fields problem.

rodvaN

Registered User.
Local time
Today, 02:58
Joined
May 20, 2009
Messages
92
Hello there.. I just the next code for required fields in a form for entry data.

Private Sub Textbox_BeforeUpdate(Cancel As Integer)
If IsNull(Me![Textbox]) Then
MsgBox "Its obligatory that you type something in this field.", vbInformation, "obligatory."

Cancel = True
End If
End Sub

----
Now it wont let me do ANYTHING until I type something in the textbox..
My question is..
How can I do a button to cancel all and close the form, because when I try to close with a close button I made, it appears the obligatory message.
How can I do a CANCEL ALL AND CLOSE button?
Thanls in advance
 
I normally have a Cancel button and an OK button on each form where the user is going to be doing data entry.

The Cancel button is always enabled and available for the user to simply decide that no data entry is required. Code behind this button just checks to see if the form is "dirty" (had had data changed) and if so it does an Undo and closes the form.

The Ok button allows the user to save any changes made to the data, however, it is always set to be disabled. I create a user defined function that will check all required fields to make sure that data entry has been provided for each of the requied fields. Only when all requirements have been met does the user defined function set the OK button to be enabled, thus allowing the user to save the record.

HTH
 
Mr. B
I realy Like you're Idea on the OK button..
Id better put the required fields then enable the save button.
But I have to make sure that it automatically do not save the data on the database.. thats Me.Dirty command right?
Can you provide the VBA code please?
 
Your function might be something like the following untested code:

Function ChkReqData()
If not isnull(me.NameOfSomeControl) and Not isNull(me.NameOfOtherControl) _
and me.NameOfNumericTypeControl > 0 then
Me.NameOfOkButton.cnabled = true
Else
Me.NameOfOkButton.Enabled = false
End IF
End function

You can add as many controls to be checked as you need. The statements I have used all check for text type fields. If you have a numeric value to be checked it would be like the part of the function "NameOfNumericControl".

In the After Update event of each of the controls on your form (and I do mean all of them) you would use this statement:
ChkReqData

This will check for the existance of data entry in the controls you specified in the function "ChkReqData" and if any of the controls being checked does meet the criteria specified in the function, the Ok button will not be enabled and cannot be used.

In the On Click event of your Ok button you and use code like:
If me.dirty = true then
'save the record
Me.Dirty = false
end if
'set the focus to some other control
me.NameOfOtherControl.setfocus
me.NameOfOkButton.enabled = false

Here you save the record move the focus to another control and make the OK button not enabled again.

HTH
 

Users who are viewing this thread

Back
Top Bottom