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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If command not working

Status
Not open for further replies.

policechiefwiggum

Programmer
Mar 19, 2006
48
GB
Hi Guys, sorry, back again!

I'm having a bit of trouble with an if command, i think i know what causing the issue but not 100% sure how to sort it.

i have a form which has a text box and a check box, if the user has not entered a value in the text box or checked the tick box i want to display an error. this is what i've written but its not working
Code:
If Me.ChkProjectManager.Value = False And Me.ProjManager.Value = "" Then
MsgBox "Please enter Project Managers name or tick box to continue"
End If

when i debug the code i seem to have an issue with
Code:
Me.ChkProjectManager.Value
fluctuating between "-1" & "False" and
Code:
Me.ProjManager.Value
fluctuating between "" & Null can i standardise how these values are being read? i need to replicate this code for 5 fields

also on a related note, once the user has checked the tick box is there anyway i can get access / VBA to identify which fields have blank text fields but checked tick boxes, rather than writing if commands for each possible scenario?

Thanks in advance
 
is not the same as Null. One solution is to use code like:
Code:
If Me.ChkProjectManager.Value = False And Me.ProjManager & "" = "" Then
    MsgBox "Please enter Project Managers name or tick box to continue"
End If

If you have 5 sets of repeating fields, perhaps you should normalize your table structure. Creating a solution that identifies the check box with text boxes might take more time than writing the repeating code.

Duane
Hook'D on Access
MS Access MVP
 
sorry, not made myself clear again!

i have 5 fields with different data that i want to run similar validation.

i have set up the table so that the text boxes are text boxes and the tick boxes are yes/no.

thanks for the above code i'll give it a bash and see if it helps :)
 
My impression is that you have a field for ProjectManager with 4 additional fields for project roles (or similar). Since you haven't provided the names of these fields, I can't be sure.

Duane
Hook'D on Access
MS Access MVP
 
Sorry, no i've got 5 values, some will be populkated in the DB some not.

I have managed to get my original code to work, what i've done is in the OnLoad i've set the value of all 5 text boxes to "" and all 5 check boxes to 0, then i've run my SQL to pull the data from the database, meaning that where there is a value, its written as expected, and where theres not the value of that field / check box is already set for my code.

a bit backwards but hey it works!! ;o)
 
Duane said:
My impression is that you have a field for ProjectManager with 4 additional fields for project roles (or similar). Since you haven't provided the names of these fields, I can't be sure.
Now you say you have 5 values? Are these in 5 records or do you have 5 fields in your table for these 5 values?

I don't understand what I can't see and you don't tell me.

Duane
Hook'D on Access
MS Access MVP
 
Here's all the code:

Code:
If Me.ChkPaCode.Value = 0 And Me.PACode.Value = "" Then
MsgBox "Please enter PA Code or tick box to continue"
End If

If Me.ChkOneView.Value = 0 And Me.Oneview123.Value = "" Then
MsgBox "Please enter OneView ID or tick box to continue"
End If

If Me.ChkDelMan.Value = 0 And Me.DelManager.Value = "" Then
MsgBox ("Please enter Delivery / Tools & Tech Managers name or tick box to continue")
End If

If Me.ChkProjectManager.Value = 0 And Me.ProjManager.Value = "" Then
MsgBox "Please enter Project Managers name or tick box to continue"
End If

If Me.ChkLaunchDate.Value = 0 And Me.LaunchDate.Value = "" Then
MsgBox "Please enter Launch Date or tick box to continue"
End If
when the form loads it pulls the value of the text fields from the database, and populates the fields where its available. if its not available, then i want to the user to tick the checkbox as acknowledgement the data is missing.

as per my previous post it seems to be working if i set the value of the field onload.
 

How about this (suggested earlier by Duane) ?
Code:
If Me.ChkPaCode.Value = 0 And Me.PACode & "" = "" Then
You might also try breaking it down to checking just the text box or just the check box. That could tell you exactly where your problem lies.


Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top