No need to appologize (I have no idea how you write this word), English is
not my main language so I hope I didn't sound to harsh (another word). I just
hope they had speller in this discssion group, and I'm to lazy to write it
first in word.
Any way, to your question.
It's all depend on what you want to do, if you want a specific message for
each field and then set the focus, then yes, you can create this criteria for
each field separetly.
And you need to add
exit sub
in each IF, so it wont prompt the user with four messages or more, it will
exit the checking on the first error
===========================================
But if the messae is not important, then you can try something like
If (IsNull(Me.[Textbox 2]) And Not IsNull(Me.[Textbox 1])) Or
(IsNull(Me.[Textbox 3]) And Not IsNull(Me.[Textbox 4])) Or
(IsNull(Me.[Textbox 5]) And Not IsNull(Me.[Textbox 6])) Or
(IsNull(Me.[Textbox 7]) And Not IsNull(Me.[Textbox 8])) Then
MsgBox "Must complete fields"
Cancel = True 'wont let the user continue
Emd If
--
\\// Live Long and Prosper \\//
BS"D
Melissa said:
You did write that and I am sorry. I did apply this in the forms before
update and it did work.
One more question on this though. I have a total of 8 fields that I want to
apply this same rule to. How would I write this as cleanly as possible? Do I
just continue writing the same thing after the Me.[TextBox 2].SetFocus and
when all 8 fields are compled write. End IF
Thanks again.
:
As I wrote in the first post, put this code in the before update event of the
form, not the text box, so the validation will happen before the record is
saved.
--
\\// Live Long and Prosper \\//
BS"D
:
I wrote this in TextBox 2 before update property and it is not working.
Should I put this in Textbox 1 after update? Sorry, I took so long in
replying but, I do appreciate your help.
:
On the before update event of the form, enter the code
If IsNull(Me.[Textbox 2]) And Not IsNull(Me.[Textbox 1]) Then
MsgBox "TextBox 2 must be filled if Text Box 1 Is"
Cancel = True 'wont let the user continue
Me.[TextBox2].SetFocus
Emd If
--
\\// Live Long and Prosper \\//
BS"D
:
In access if a user enters data in Textbox 1 for example and does not enter
data into Textbox 2, how can I code that to say,
"If data is in Txtbox 1 then Txtbox 2 is required to be completed? Is there
a simple code you could help me with?
Thanks