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!

Text box

Status
Not open for further replies.

Cretin

Technical User
Jan 2, 2003
194
US
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, , _
&quot;A.Date_of_Incident >= #&quot; & stfromdate & &quot;# And A.Date_of_Incident <= #&quot; & sttodate & &quot;# And A.Last_Name = &quot; & stlname & &quot; And A.First_Name = &quot; & stfname

End If

Any help woold be appreciated
 
It appears the query used for the reports has parameters. Access does not let you assign a recordsource for a report at run time. I get around this by letting the recordsource be a temporary table that is filled with the data (based on user parameters).

Do you need example code?
 
Yes thanks. i have another form and the followinf code does work:

DoCmd.OpenReport stdocname, acViewPreview, , _
&quot;A.Date_of_Incident = #&quot; & stfromdate & &quot;#&quot;
Else

DoCmd.OpenReport stdocname, acViewPreview, , _
&quot;A.Date_of_Incident >= #&quot; & stfromdate & _
&quot;# and A.Date_of_Incident <= #&quot; & sttodate & &quot;#&quot;


I thought maybe because in the other form I am having trouble with I am using a string and a date where in the form that works I am using a only date but if you have a sample code I would appreciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top