Before update on form

  • Thread starter Thread starter Bob Vance
  • Start date Start date
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
 
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.
 
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
 
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
 
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
 
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
 
Back
Top