I have a form with 4 input fields, a from date, a to date, a first name and a last name. I input data into all 4 fields. Then I click on a button to generate a report which has a build event in it thats vb code. Instead of getting a report I get input boxes the first one says first name, I input the first name, then a box with the persons first name on the heading appears again I put in the first name, then a box for the last name I key that in then a box with the persons last name as heading I put that in then I get the proper report. Here is my code:
Dim stdocname As String
Dim stfromdate As String
Dim sttodate As String
Dim stfname As String
Dim stlname As String
txtfromdate.SetFocus
stfromdate = txtfromdate.Text
If txtfromdate.Text = "" Then
MsgBox "You need a start date", vbOKOnly
Exit Sub
End If
txttodate.SetFocus
sttodate = txttodate.Text
If txttodate.Text = "" Then
MsgBox "You need a end date", vbOKOnly
Exit Sub
End If
txtfname.SetFocus
stfname = txtfname.Text
If txtfname.Text = "" Then
MsgBox "You need a first name", vbOKOnly
Exit Sub
End If
txtlname.SetFocus
stlname = txtlname.Text
If txtlname.Text = "" Then
MsgBox "You need a last name", vbOKOnly
Exit Sub
End If
If stfromdate = sttodate Then
DoCmd.OpenReport stdocname, acViewPreview, , _
"A.Date_of_Incident = #" & stfromdate & "# And A.Last_Name = " & stlname & " And A.First_Name = " & stfname
Else
DoCmd.OpenReport stdocname, acViewPreview, , _
"A.Date_of_Incident >= #" & stfromdate & "# And A.Date_of_Incident <= #" & sttodate & "# And A.Last_Name = " & stlname & " And A.First_Name = " & stfname
End If
Any help woold be appreciated
Dim stdocname As String
Dim stfromdate As String
Dim sttodate As String
Dim stfname As String
Dim stlname As String
txtfromdate.SetFocus
stfromdate = txtfromdate.Text
If txtfromdate.Text = "" Then
MsgBox "You need a start date", vbOKOnly
Exit Sub
End If
txttodate.SetFocus
sttodate = txttodate.Text
If txttodate.Text = "" Then
MsgBox "You need a end date", vbOKOnly
Exit Sub
End If
txtfname.SetFocus
stfname = txtfname.Text
If txtfname.Text = "" Then
MsgBox "You need a first name", vbOKOnly
Exit Sub
End If
txtlname.SetFocus
stlname = txtlname.Text
If txtlname.Text = "" Then
MsgBox "You need a last name", vbOKOnly
Exit Sub
End If
If stfromdate = sttodate Then
DoCmd.OpenReport stdocname, acViewPreview, , _
"A.Date_of_Incident = #" & stfromdate & "# And A.Last_Name = " & stlname & " And A.First_Name = " & stfname
Else
DoCmd.OpenReport stdocname, acViewPreview, , _
"A.Date_of_Incident >= #" & stfromdate & "# And A.Date_of_Incident <= #" & sttodate & "# And A.Last_Name = " & stlname & " And A.First_Name = " & stfname
End If
Any help woold be appreciated