A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Form Validation help



 
 
Thread Tools Display Modes
  #1  
Old December 8th, 2006, 08:30 AM posted to microsoft.public.access.forms
Andy
external usenet poster
 
Posts: 941
Default Form Validation help

I have a form where users can select items from a drop-down box as well as
manually enter data if they wish. I want to build in a validation rule where
a warning is displayed if the user tries to enter data where the first 4
characters do not exist in another table...

Presume some form of left([Data],4) and Iif and lookup functions, but can't
get anything to work properly.

Thanks
  #2  
Old December 8th, 2006, 09:15 AM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Form Validation help

You use a combo for this field, provided its bound column is not hidden
(i.e. the value you see is actually the value being saved into the field.)

You could then use the BeforeUpdate event of the combo to DLookup() the
field in the other table.

This kind of thing:

Private Sub Combo1_BeforeUpate(Cancel As Integer)
Dim strWhere As String
Dim varResult As Variant
Dim strMsg As String

With Me.[Combo1]
If Not IsNull(.Value) Then
strWhere = "[MyLookupField] Like """ & Left(.Value, 4) &
"*"""
varResult = DLookup("MyLookupField", "MyTable", strWhere)
If IsNull(varResult) Then
strMsg = "Doesn't match." & vbCrLf & "Continue anyway?"
If MsgBox(strMsg, vbYesNo+vbDefaultButton2) = vbNo Then
Cancel = True
End If
End If
End If
End With
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Andy" wrote in message
...
I have a form where users can select items from a drop-down box as well as
manually enter data if they wish. I want to build in a validation rule
where
a warning is displayed if the user tries to enter data where the first 4
characters do not exist in another table...

Presume some form of left([Data],4) and Iif and lookup functions, but
can't
get anything to work properly.

Thanks



  #3  
Old December 8th, 2006, 11:00 AM posted to microsoft.public.access.forms
Andy
external usenet poster
 
Posts: 941
Default Form Validation help

Thanks for the reply, though my VBA knowledge is limited. Is there any web
pages you could recommend?

"Allen Browne" wrote:

You use a combo for this field, provided its bound column is not hidden
(i.e. the value you see is actually the value being saved into the field.)

You could then use the BeforeUpdate event of the combo to DLookup() the
field in the other table.

This kind of thing:

Private Sub Combo1_BeforeUpate(Cancel As Integer)
Dim strWhere As String
Dim varResult As Variant
Dim strMsg As String

With Me.[Combo1]
If Not IsNull(.Value) Then
strWhere = "[MyLookupField] Like """ & Left(.Value, 4) &
"*"""
varResult = DLookup("MyLookupField", "MyTable", strWhere)
If IsNull(varResult) Then
strMsg = "Doesn't match." & vbCrLf & "Continue anyway?"
If MsgBox(strMsg, vbYesNo+vbDefaultButton2) = vbNo Then
Cancel = True
End If
End If
End If
End With
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Andy" wrote in message
...
I have a form where users can select items from a drop-down box as well as
manually enter data if they wish. I want to build in a validation rule
where
a warning is displayed if the user tries to enter data where the first 4
characters do not exist in another table...

Presume some form of left([Data],4) and Iif and lookup functions, but
can't
get anything to work properly.

Thanks




  #4  
Old December 8th, 2006, 02:10 PM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Form Validation help

If you need help with DLookup(), see:
http://allenbrowne.com/casu-07.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Andy" wrote in message
news
Thanks for the reply, though my VBA knowledge is limited. Is there any web
pages you could recommend?

"Allen Browne" wrote:

You use a combo for this field, provided its bound column is not hidden
(i.e. the value you see is actually the value being saved into the
field.)

You could then use the BeforeUpdate event of the combo to DLookup() the
field in the other table.

This kind of thing:

Private Sub Combo1_BeforeUpate(Cancel As Integer)
Dim strWhere As String
Dim varResult As Variant
Dim strMsg As String

With Me.[Combo1]
If Not IsNull(.Value) Then
strWhere = "[MyLookupField] Like """ & Left(.Value, 4) &
"*"""
varResult = DLookup("MyLookupField", "MyTable", strWhere)
If IsNull(varResult) Then
strMsg = "Doesn't match." & vbCrLf & "Continue
anyway?"
If MsgBox(strMsg, vbYesNo+vbDefaultButton2) = vbNo
Then
Cancel = True
End If
End If
End If
End With
End Sub

"Andy" wrote in message
...
I have a form where users can select items from a drop-down box as well
as
manually enter data if they wish. I want to build in a validation rule
where
a warning is displayed if the user tries to enter data where the first
4
characters do not exist in another table...

Presume some form of left([Data],4) and Iif and lookup functions, but
can't
get anything to work properly.



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:30 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.