Before update on form

B

Bob Vance

Just cant work out the tbName must have the character "#" in tbName if
ckb2ndCompany is true!
Dim iAns As Integer
If Me![ckb2ndCompany] = -1 & [tbName]dosent contain the "#" Then
Cancel = True
iAns = MsgBox("Please enter the symbel # first!! " _
& "Click OK to Enter # or Cancel to quit", vbOKCancel)
If iAns = vbOK Then
Me.tbName.SetFocus
Else
Me.Undo
End If
End If
 
A

Allen Browne

Open the table in design view, and add a Validation Rule on the table:
([chk2ndCompany] = False) OR ([tbName] Like "*[#]*")

Note that goes into the Properties box, not beside the Validation Rule for a
field (in the lower pane of table design.)

More info on validation rules:
http://allenbrowne.com/ValidationRule.html

If you want to use VBA code instead, try:
Instr([tbName], "#") > 0
Returns a number greater than zero if found.
 
B

Bob Vance

Thanks Allen, could not get the Validation Rule to work so how could I code
it with a msgbox to say [OwnerLastName] does not contain "#" and cant be
saved, when 2ndCompany is selected
Thanks bob vance

Allen Browne said:
Open the table in design view, and add a Validation Rule on the table:
([chk2ndCompany] = False) OR ([tbName] Like "*[#]*")

Note that goes into the Properties box, not beside the Validation Rule for
a field (in the lower pane of table design.)

More info on validation rules:
http://allenbrowne.com/ValidationRule.html

If you want to use VBA code instead, try:
Instr([tbName], "#") > 0
Returns a number greater than zero if found.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Bob Vance said:
Just cant work out the tbName must have the character "#" in tbName if
ckb2ndCompany is true!
Dim iAns As Integer
If Me![ckb2ndCompany] = -1 & [tbName]dosent contain the "#" Then
Cancel = True
iAns = MsgBox("Please enter the symbel # first!! " _
& "Click OK to Enter # or Cancel to quit", vbOKCancel)
If iAns = vbOK Then
Me.tbName.SetFocus
Else
Me.Undo
End If
End If
 
B

Bob Vance

Oh Sorry Allen It does work
([2ndCompany]=True) And ([OwnerLastName] Like "*[#]*")
But I need a error box to tell them why it wont save!
Regards Bob Vance

Allen Browne said:
Open the table in design view, and add a Validation Rule on the table:
([chk2ndCompany] = False) OR ([tbName] Like "*[#]*")

Note that goes into the Properties box, not beside the Validation Rule for
a field (in the lower pane of table design.)

More info on validation rules:
http://allenbrowne.com/ValidationRule.html

If you want to use VBA code instead, try:
Instr([tbName], "#") > 0
Returns a number greater than zero if found.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Bob Vance said:
Just cant work out the tbName must have the character "#" in tbName if
ckb2ndCompany is true!
Dim iAns As Integer
If Me![ckb2ndCompany] = -1 & [tbName]dosent contain the "#" Then
Cancel = True
iAns = MsgBox("Please enter the symbel # first!! " _
& "Click OK to Enter # or Cancel to quit", vbOKCancel)
If iAns = vbOK Then
Me.tbName.SetFocus
Else
Me.Undo
End If
End If
 
A

Allen Browne

Put your message in the Validation Text property (just below the Validation
Rule.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Bob Vance said:
Oh Sorry Allen It does work
([2ndCompany]=True) And ([OwnerLastName] Like "*[#]*")
But I need a error box to tell them why it wont save!
Regards Bob Vance

Allen Browne said:
Open the table in design view, and add a Validation Rule on the table:
([chk2ndCompany] = False) OR ([tbName] Like "*[#]*")

Note that goes into the Properties box, not beside the Validation Rule
for a field (in the lower pane of table design.)

More info on validation rules:
http://allenbrowne.com/ValidationRule.html

If you want to use VBA code instead, try:
Instr([tbName], "#") > 0
Returns a number greater than zero if found.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Bob Vance said:
Just cant work out the tbName must have the character "#" in tbName if
ckb2ndCompany is true!
Dim iAns As Integer
If Me![ckb2ndCompany] = -1 & [tbName]dosent contain the "#" Then
Cancel = True
iAns = MsgBox("Please enter the symbel # first!! " _
& "Click OK to Enter # or Cancel to quit", vbOKCancel)
If iAns = vbOK Then
Me.tbName.SetFocus
Else
Me.Undo
End If
End If
 
R

Rudolf

Bob Vance said:
Just cant work out the tbName must have the character "#" in tbName if
ckb2ndCompany is true!
Dim iAns As Integer
If Me![ckb2ndCompany] = -1 & [tbName]dosent contain the "#" Then
Cancel = True
iAns = MsgBox("Please enter the symbel # first!! " _
& "Click OK to Enter # or Cancel to quit", vbOKCancel)
If iAns = vbOK Then
Me.tbName.SetFocus
Else
Me.Undo
End If
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top