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

Problem with code

Status
Not open for further replies.

vilmarie

Programmer
Feb 10, 2004
41
PR
I need that if the person don't fill any field in a form and press the button "Open ReportByDate" then appear a msgbox that indicate:please fill any field. If the person fill any field then open a "rptBySelectionReportForm". The code is the following, but this not funtion, please help me in this code.


Private Sub cmdOpenReportByDate_Click()
Dim stDocName As String


If IsNull(Me![txtByDate]) Or (Me![txtCompany]) Or (Me![txtTimeIn]) Or (Me![txtTypeOfPerson]) Or (Me![Check14]) = " " Then
MsgBox "Please fill any field", vbOKOnly, "Error!!!"
Me![txtByDate].SetFocus
Exit Sub

End If


stDocName = "rptBySelectionReportForm"
DoCmd.OpenReport stDocName, acPreview
DoCmd.OpenReport stDocName, acPreview
DoCmd.RunCommand acCmdZoom100

End Sub
 
Do you want to ensure that all fields have been populated, or simply that at least one of them has been populated?

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I think he wants to make sure at least one is filled, Cajun. In which case I'd try changing the Ors to Ands.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
I need to ensure that at least one filed is filled.
 
I change the OR by AND but the code not realize the if.

Private Sub cmdOpenReportByDate_Click()
Dim stDocName As String


If IsNull(Me![txtByDate]) And (Me![txtCompany]) And (Me![txtTimeIn]) And (Me![txtTypeOfPerson]) And (Me![Check14]) = " " Then
MsgBox "Please fill any field", vbOKOnly, "Error!!!"
Me![txtByDate].SetFocus
Exit Sub

End If


stDocName = "rptBySelectionReportForm"
DoCmd.OpenReport stDocName, acPreview
DoCmd.OpenReport stDocName, acPreview
DoCmd.RunCommand acCmdZoom100

End Sub
 
Try putting ="" after each of the conditions in the If statement.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Okey, I put ="" to each condition, but obtain an error: 'Type mismatch'
 
My fault. I wasn't paying attention. What happens if you use this line:
If IsNull(Me![txtByDate]) And (Me![txtCompany]) And (Me![txtTimeIn]) And (Me![txtTypeOfPerson]) And (Me![Check14])Then

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Okey: I insert the following:

Private Sub cmdOpenReportByDate_Click()
Dim stDocName As String


If IsNull((Me![txtByDate]) = "" And (Me![txtCompany]) = "" And (Me![txtTimeIn]) = "" And (Me![txtTypeOfPerson]) = "" And (Me![Check14])) = "" Then
MsgBox "Please fill any field", vbOKOnly, "Error!!!"
Me![txtByDate].SetFocus
Exit Sub

End If


stDocName = "rptBySelectionReportForm"
DoCmd.OpenReport stDocName, acPreview
DoCmd.OpenReport stDocName, acPreview
DoCmd.RunCommand acCmdZoom100

End Sub

and obtain the following error: " Type mismatch
 
Have you tried this ?
If Len(Trim(Nz(txtByDate,"") & Nz(txtCompany,"") & Nz(txtTimeIn,"") & Nz(txtTypeOfPerson,"") & Nz(Check14,""))) = 0 Then


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I try this later, thanks for you help. I am going to lunch!!! smile
 
Thanks for you help, this code is perfect an realize teh work, thanks!!!
 
Your original syntax was wrong...

If IsNull(Me![txtByDate]) Or (Me![txtCompany]) Or (Me![txtTimeIn]) Or (Me![txtTypeOfPerson]) Or (Me![Check14]) = " " Then

should be..
If IsNull(Me![txtByDate]) OR
IsNull(Me![txtCombany]) OR
IsNull(Me![txtTimeIn] OR
IsNull(Me![txtTypeOfPerson]) OR
isNull(Me![Check14]) Then




Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top