Need some Help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 2 different fields in my database and i need to be able to have the db
check these two fields to make sure that the same serial number doesnt come
in both fields
eg, model A 1234
model B 1234

i need something that will be able to check the serial number to make sure
that it is unique.

Cheers
 
Put the following code in the BeforeUpdate event of the first textbox:
If Me!NameOfFirstTextbox = Me!NameOfSecondTextBox Then
MsgBox "Same As Second TextBox - Enter Different Serial#"
Me!NameOfFirstTextBox.Undo
End If

Put the following code in the BeforeUpdate event of the second textbox:
If Me!NameOfSecondTextbox = Me!NameOfFirstTextBox Then
MsgBox "Same As First TextBox - Enter Different Serial#"
Me!NameOfSecondTextBox.Undo
End If

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)
 
Use the form's BeforeUpdate event to test the values in the two fields (or
in the controls bound to those fields):

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.ModelAControlName.Value = Me.ModelBControlName.Value Then
MsgBox "Same value in both textboxes."
Cancel = True
End If
End Sub
 
Hi Nightscale

I think your question is saying that you are entering details of models
(Model Name + Serial Number) on a form and you want to check to make sure the
same deatils haven't alreadu been saved in your table? If so, then in the
input Control's BeforeUpdate Event use the following code.

Assuming that the table is called Models, the Model name, Model, Serial
Number SN and the control Text1 for Model Name and Text2 for its Serial
Number, then code:

If DCount("SN", "Models", "Model = '" & Me.Text1 & "' And SN = '" & Me.Text2
& "'") > 0 then
MsgBox "The Serial Number has already been used."
End If

Note that the first '" is, exagerated, ' ", the second is " ' and the last
combination is " ' ".

Cheers.

BW
 
Back
Top