Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control Validation

Status
Not open for further replies.

Stargrove

Technical User
Feb 3, 2003
8
US
I have two fields on my form:
- HoldFor is a CheckBox field
- ProjectID is a Text field

I have the following code:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me![HoldFor] = True And [ProjectID] = Null Then
   DoCmd.RunMacro("mcrReserved") ' Displays warning message
   DoCmd.GoToControl "ProjectID"
   Cancel = True
End If

End Sub
Problem:
- Does not work %-)

What I see:
- When I set the first line of the IF statement for Debug I can see that [HoldFor] is True and [ProjectID] is Null by mousing over them. I then continue running the code and none of the subsequest code gets executed. I am not sure why since both tests are true.

I basically want the user to have to put text into the [ProjectID] field if [HoldFor] is checked. If there is a better way to do this than the way I am trying to, please let me know. I have thought about a validation rule in the controls or underlying table, but I do not know how to implement that properly.

Thanks in advance for any help.

James
 
One of the more reliable ways of testing for Null (and empty string) is

[tt]If Me![HoldFor] = True And trim$([ProjectID] & "" ) "" Then[/tt]

Roy-Vidar
 
Ouch - perhaps have a little equal sign within too...

[tt]If Me![HoldFor] = True And trim$([ProjectID] & "" ) = "" Then[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top