Hi
I have created a temporary ado recordset (I had to add some empty rows into and existing recordset). The recordset has now the correct number of rows and I can navigate through them just fine.
But so far I have been out-of-luck trying to get a report to use that recordset as its recordsource. Here is some of my code (I tried to have the code on a click of a button on a form and I also tried to have it in the report_open event. I also tried to open a form instead of a report and I also tried to save the recordset with adPersistADTG and loading it again):
Dim db As DAO.Database
Dim rso As DAO.Recordset
Dim rst As ADODB.Recordset
Dim i As Integer
Dim rcount As Integer
Dim membercount As Integer
Dim CalRec As Integer
Dim sqlstr As String
Dim startDate As Date
startDate = DateValue("05/14/01" //Just an example date
Set db = CurrentDb()
Set rso = db.OpenRecordset("members", dbOpenTable)
membercount = rso.RecordCount
rso.Close
Set rst = New ADODB.Recordset
rst.Fields.Append "name", adVarChar, 60
rst.Fields.Append "monday", adVarChar, 15
rst.Fields.Append "tuesday", adVarChar, 15
rst.Fields.Append "wednesday", adVarChar, 15
rst.Fields.Append "thursday", adVarChar, 15
rst.Fields.Append "friday", adVarChar, 15
rst.Fields.Append "BeginDate", adDate
rst.Fields.Append "Enddate", adDate
rst.Open
For i = 1 To judgecount
sqlstr = "SELECT members.*, calnew.* FROM calnew RIGHT JOIN members ON calnew.memberid = members.memberid WHERE calnew.memberid = " _
& i & " AND calnew.weekid = DateValue('" & startDate & "')"
Set rso = db.OpenRecordset(sqlstr)
If rso.BOF And rso.EOF Then
rcount = 0
rso.Close
Set rso = db.OpenRecordset("SELECT members.* FROM members WHERE members.memberid = " & i)
Else
rso.MoveLast
rcount = rso.RecordCount
rso.MoveFirst
End If
If rcount > 0 Then
For CalRec = 1 To rcount
rst.AddNew Array("name", "monday", "tuesday", "wednesday", "thursday", "friday", "Begindate", "Enddate", _
Array(Trim(rso![last]) & " " & Trim(rso![middle]) & " " & Trim(rso![first]), IIf(IsNull(rso![monday]), "", rso![monday]), IIf(IsNull(rso![tuesday]), "", rso![tuesday]), _
IIf(IsNull(rso![wednesday]), "", rso![wednesday]), IIf(IsNull(rso![thursday]), "", rso![thursday]), IIf(IsNull(rso![friday]), "", rso![friday]), DateValue(startDate), DateAdd("y", 4, DateValue(startDate)))
rso.MoveNext
Next CalRec
rso.MoveFirst
End If
If rcount < 5 Then
For CalRec = 1 To (5 - rcount)
rst.AddNew Array("name", "monday", "tuesday", "wednesday", "thursday", "friday", "Begindate", "Enddate", _
Array(Trim(rso![last]) & " " & Trim(rso![middle]) & " " & Trim(rso![first]), "", "", "", "", "", DateValue(startDate), _
DateAdd("y", 4, DateValue(startDate)))
Next CalRec
End If
rso.Close
Next i
rst.UpdateBatch
rst.MoveFirst
DoCmd.OpenReport "Report5", acViewPreview //In this case I declared rst as a global variable in a standard class module
'rst.Close
'Me.RecordSource = rst //This I used in the report_open event
' rst.Save "c:\temp\cal.adtg", adPersistADTG //Trying to save it as a file for later use
' rst.Close
' DoCmd.OpenForm "Form1", windowmode:=acHidden //Trying to open a form instead of a report
' With Forms("Form1"
' Set .Recordset = rst
' .Visible = True
' End With
rst.Close
Set rst = Nothing
Set rso = Nothing
Set db = Nothing
======================================================
No matter which one of the above I try I always get the error:
Run-Time Error 7965: The object your entered is not a valid Recordset Property.
The debugger will be on the line that I try to assign the recordset to the recordsource/recordset of the report or form.
Am I just missing a simple thing or is this just not feasable this way? The recordset has all the rows I need and as this is going to be used from more than one person I didn't want to create physical tables for this very temporary data.
Thanks in advance for any hint/suggestions
Serge
I have created a temporary ado recordset (I had to add some empty rows into and existing recordset). The recordset has now the correct number of rows and I can navigate through them just fine.
But so far I have been out-of-luck trying to get a report to use that recordset as its recordsource. Here is some of my code (I tried to have the code on a click of a button on a form and I also tried to have it in the report_open event. I also tried to open a form instead of a report and I also tried to save the recordset with adPersistADTG and loading it again):
Dim db As DAO.Database
Dim rso As DAO.Recordset
Dim rst As ADODB.Recordset
Dim i As Integer
Dim rcount As Integer
Dim membercount As Integer
Dim CalRec As Integer
Dim sqlstr As String
Dim startDate As Date
startDate = DateValue("05/14/01" //Just an example date
Set db = CurrentDb()
Set rso = db.OpenRecordset("members", dbOpenTable)
membercount = rso.RecordCount
rso.Close
Set rst = New ADODB.Recordset
rst.Fields.Append "name", adVarChar, 60
rst.Fields.Append "monday", adVarChar, 15
rst.Fields.Append "tuesday", adVarChar, 15
rst.Fields.Append "wednesday", adVarChar, 15
rst.Fields.Append "thursday", adVarChar, 15
rst.Fields.Append "friday", adVarChar, 15
rst.Fields.Append "BeginDate", adDate
rst.Fields.Append "Enddate", adDate
rst.Open
For i = 1 To judgecount
sqlstr = "SELECT members.*, calnew.* FROM calnew RIGHT JOIN members ON calnew.memberid = members.memberid WHERE calnew.memberid = " _
& i & " AND calnew.weekid = DateValue('" & startDate & "')"
Set rso = db.OpenRecordset(sqlstr)
If rso.BOF And rso.EOF Then
rcount = 0
rso.Close
Set rso = db.OpenRecordset("SELECT members.* FROM members WHERE members.memberid = " & i)
Else
rso.MoveLast
rcount = rso.RecordCount
rso.MoveFirst
End If
If rcount > 0 Then
For CalRec = 1 To rcount
rst.AddNew Array("name", "monday", "tuesday", "wednesday", "thursday", "friday", "Begindate", "Enddate", _
Array(Trim(rso![last]) & " " & Trim(rso![middle]) & " " & Trim(rso![first]), IIf(IsNull(rso![monday]), "", rso![monday]), IIf(IsNull(rso![tuesday]), "", rso![tuesday]), _
IIf(IsNull(rso![wednesday]), "", rso![wednesday]), IIf(IsNull(rso![thursday]), "", rso![thursday]), IIf(IsNull(rso![friday]), "", rso![friday]), DateValue(startDate), DateAdd("y", 4, DateValue(startDate)))
rso.MoveNext
Next CalRec
rso.MoveFirst
End If
If rcount < 5 Then
For CalRec = 1 To (5 - rcount)
rst.AddNew Array("name", "monday", "tuesday", "wednesday", "thursday", "friday", "Begindate", "Enddate", _
Array(Trim(rso![last]) & " " & Trim(rso![middle]) & " " & Trim(rso![first]), "", "", "", "", "", DateValue(startDate), _
DateAdd("y", 4, DateValue(startDate)))
Next CalRec
End If
rso.Close
Next i
rst.UpdateBatch
rst.MoveFirst
DoCmd.OpenReport "Report5", acViewPreview //In this case I declared rst as a global variable in a standard class module
'rst.Close
'Me.RecordSource = rst //This I used in the report_open event
' rst.Save "c:\temp\cal.adtg", adPersistADTG //Trying to save it as a file for later use
' rst.Close
' DoCmd.OpenForm "Form1", windowmode:=acHidden //Trying to open a form instead of a report
' With Forms("Form1"
' Set .Recordset = rst
' .Visible = True
' End With
rst.Close
Set rst = Nothing
Set rso = Nothing
Set db = Nothing
======================================================
No matter which one of the above I try I always get the error:
Run-Time Error 7965: The object your entered is not a valid Recordset Property.
The debugger will be on the line that I try to assign the recordset to the recordsource/recordset of the report or form.
Am I just missing a simple thing or is this just not feasable this way? The recordset has all the rows I need and as this is going to be used from more than one person I didn't want to create physical tables for this very temporary data.
Thanks in advance for any hint/suggestions
Serge