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

Setting a Report's Record Set 1

Status
Not open for further replies.

BAWC01

Technical User
Nov 23, 2005
79
CH
Hi

I have a form and a Subform

I succesfully get the records I need to appear in the subform.

I would like then to pass these records and the recordset into a report to print.

How do I do that ?

Thanks

Phil
 
If you're after specificly assigning the recordset, that feature, I think is only available in 2002 and later versions, but not for mdbs, only ADP's.

For mdbs, I think you'll have to use a table, query or sql string.

One "pseudo" method of assigning a dao recordset to a report, is to assign the recordsets name property to the recordsource of the report, which will assign whatever is the source of the recordset to the recordsource of the report.

Say in the reports on open event

[tt]if ((not rs.bof) and (not rs.eof)) then
me.recordsource = rs.name
else
cancel = true
endif[/tt]

Roy-Vidar
 
Roy

Thanks for that I have done the following

Code:
Private Sub Report_Open(Cancel As Integer)

If ((Not rs.BOF) And (Not rs.EOF)) Then
    Me.RecordSource = rs.rstHUTF
Else
    Cancel = True
End If

End Sub

but get the following error when I press the print button on the form.

Code:
Run time error '424'
Object Required

 
How have you declared and instantiated (opened) the recordset? Is it availabe within the scope of the report?

Roy-Vidar
 
Roy

I have declared it globally
Code:
Public rstHUTF As DAO.Recordset

Then populate it the following way

Code:
Private Sub cmbULD_ID_AfterUpdate()
Dim dbsCurrent As Database
'Dim rstHUTF As DAO.Recordset  === Globally Set

GULD_ID = Mid(cmbULD_ID.Value, 4, 5)
GULD_Carrier = Mid(Me.cmbULD_ID.Value, 9, 2)
GULD_Full_ID = cmbULD_ID.Value
        
Set dbsCurrent = CurrentDb
Set rstHUTF = dbsCurrent.OpenRecordset( _
              "SELECT STAMP, OPCOO, AREA, FLOW, USTATE, UCAT, WEIGHT, SHC, ULDID, INFLTID, OUTFLTID, DEST " _
            & "FROM HIS_HUTF " _
            & "WHERE ULDID like '" & GULD_Full_ID & "' " _
            & "ORDER BY STAMP DESC, ULDID DESC", dbOpenDynaset)

With rstHUTF
If .RecordCount = 0 Then
  MsgBox "No Records"
Else
   HUFT_ULD_Trace_Details.Visible = True
   .MoveLast
   .MoveFirst
   Set Forms!HUFT_ULD_TRACE!HUFT_ULD_Trace_Details.Form.Recordset = rstHUTF
End If
End With
End Sub

Thanks

Phil
 
Works on my setup, what I didn't see properly, is your assigning, you need to assign the name property of the recordset

[tt]Me.RecordSource = rstHUTF.Name[/tt]

Also, I think I'd recommend placing Option Explicit at the top of every module. In VBE - Tools | Options, check "Require Variable Declaration" to make have it automatically in all new modules.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top