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!

Populate reports with VBA code - General Info

Status
Not open for further replies.

sanders720

Programmer
Aug 2, 2001
421
US
I have a recordset that I wish to use to populate my report. My problem is, it is only populating the one row located in the detail area. I am certain I am missing whatever is needed to add rows to the report in code and have them populated.

Can comeone please provide some general guidance.

Thanks for your help on this!


Private Sub GetRecordset1()

Dim rs As ADODB.Recordset
Dim sql As String
Dim c As Integer
Dim rc As Integer

sql = &quot;SELECT * FROM TimeCards WHERE (((Timecards.Date)>=#&quot; & txtPS.Value & &quot;# AND (Timecards.Date)<=#&quot; & txtPE.Value & &quot;#) AND ((TimeCards.[Employee Number])=&quot; & Me.txtEN.Value & &quot;))&quot;
Debug.Print sql
Set rs = New ADODB.Recordset


With rs
.CursorLocation = adUseClient
.Open sql, CurrentProject.Connection, adOpenDynamic, adLockOptimistic

.MoveLast
rc = .RecordCount
.MoveFirst

For c = 1 To rc
Me.txtJobNumber.Value = .Fields(&quot;Job Number&quot;)
Me.txtOrderNumber.Value = .Fields(&quot;Order Number&quot;)
Me.txtOperationNumber.Value = .Fields(&quot;Op Number&quot;)
MsgBox &quot;Press Key&quot;
.MoveNext
Next c

End With

rs.Close
Set rs = Nothing


End Sub
 
Forgive for asking this but....why not just use the SQL as the report datasource and set up a normal report?

What benefit would VBA code offer?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top