..I have two fields - [sale_company] and [list_company]. At least one of these two fields must have our office name (LTC) in it (both could have it). I want a validation rule (or something) to assure us that we didn't inadvertantly forget to enter LTC in one of the fields.
Hi,
A few questions first...
What kind of data do the fields [sale_company] and [list_company] contain. Why would you want only one of the two to hold LTC. If one field is a field for your company name, that should have a default value of "LTC". If they hold some other company besides yours, then I would add a field to the table that contains these fields, and make the default value of that field "LTC".
If you
have to check for "LTC" to be in one of those two already existing fields, I would allow form entry only to the table you need to validate. Go to the form properties and turn 'navigation buttons' off. Insert a pushbutton using the wizard, and have it select the next record. Add another button to create a new record. Now, with these two buttons you have an event to trigger your validation test.
Now I need more info. Will "LTC" be at the beginning or end of the string? Will it ever be preceded by symbols, like quotes. If its at the end, is there ever anything after it? You can test the whole string for "LTC" anywhere in it, too.
The only way I can think of would be to use the replace formula(I know there's a better way) and test the two fields like:
edited out because the code below is better,
edit:<pre>Private Sub Command0_Click()
If IsNull(Txt1) Or IsNull(Txt2) Then
MsgBox ("Enter Data in Both Fields")
Exit Sub
End If
If InStr(Txt1, "LTC") = 0 And InStr(Txt2, "LTC") = 0 Then
MsgBox ("Put LTC Somewhere, fool!")
Exit Sub
Else:
Application.DoCmd.GoToRecord , , acNewRec
End If
End Sub</pre>
HTH,
____________<EMBED src=http://mitglied.lycos.de/corticus/sig.swf width=170 height=70>
Corticus@TheOfficeExperts.com
TheOfficeExperts.com
This message was edited by corticus on 2003-01-07 16:37
This message was edited by corticus on 2003-01-13 10:30