I have a query that i built that consists of 2 rows. A date from the first row is to be put in 2 places on a report, and a date from the second row is to be put in 2 other places on the same report. I posted this in Other Access problems a guy wrote back and said i needed to use vba to do this. This is what he suggested:
Dim db as Database
Dim rs as Recordset
Dim Date1 As Date
Dim Date2 As Date
Set db = CurrentDB()
Set rs = db.OpenRecordset("NameOfQuery"
Date1 = rs!DateFieldName
rs.MoveNext
Date2 = rs!DateFieldName
Me.ReportControlName = Date1
Me.ReportControlName = Date2
rs.Close
Set rs = Nothing
Set db = Nothing
ok now that was to put the dates in one spot each on the form, but come to find out i needed two so i modified it to look like this:
Private Sub Report_Open(Cancel As Integer)
Dim db As Database
Dim rs As Recordset
Dim Date1 As Date
Dim Date2 As Date
Set db = CurrentDb()
Set rs = db.OpenRecordset("LastInspectionDate"
Date1 = rs!DateOf
rs.MoveNext
Date2 = rs!DateOf
Me.Current1 = Date1
Me.Current2 = Date1
Me.Last1 = Date2
Me.Last2 = Date2
rs.Close
Set rs = Nothing
Set db = Nothing
I get a too few parameters in the statement
Set rs = db.OpenRecordset("LastInspectionDate"
LastInspectionDate is the name of the query
DateOf is my Field in my Query
Current1, Current2, Last1, Last2 are the textboxes that need to be filled. Did I do this right or wrong?
Any help would be greatly appreciated.
Bill
Dim db as Database
Dim rs as Recordset
Dim Date1 As Date
Dim Date2 As Date
Set db = CurrentDB()
Set rs = db.OpenRecordset("NameOfQuery"
Date1 = rs!DateFieldName
rs.MoveNext
Date2 = rs!DateFieldName
Me.ReportControlName = Date1
Me.ReportControlName = Date2
rs.Close
Set rs = Nothing
Set db = Nothing
ok now that was to put the dates in one spot each on the form, but come to find out i needed two so i modified it to look like this:
Private Sub Report_Open(Cancel As Integer)
Dim db As Database
Dim rs As Recordset
Dim Date1 As Date
Dim Date2 As Date
Set db = CurrentDb()
Set rs = db.OpenRecordset("LastInspectionDate"
Date1 = rs!DateOf
rs.MoveNext
Date2 = rs!DateOf
Me.Current1 = Date1
Me.Current2 = Date1
Me.Last1 = Date2
Me.Last2 = Date2
rs.Close
Set rs = Nothing
Set db = Nothing
I get a too few parameters in the statement
Set rs = db.OpenRecordset("LastInspectionDate"
LastInspectionDate is the name of the query
DateOf is my Field in my Query
Current1, Current2, Last1, Last2 are the textboxes that need to be filled. Did I do this right or wrong?
Any help would be greatly appreciated.
Bill