I am trying to pass a parameter value from a query to use in my recordset. The parameter value comes from a form but I am getting a datatype conversion error when when assigning the recordset to use the querydef param. Below is the code I have and a screenshot of the query is attached.
The main idea is to scroll through the results of the parameter query and store values to a temporary table
[IMGNOTHUMB]http://bytes.com/attachments/attachment/5535d1318961127/qry_param.jpg[/IMGNOTHUMB]
The main idea is to scroll through the results of the parameter query and store values to a temporary table
Code:
Option Explicit
Public Sub PumpOverTimes()
Dim MyDB As Dao.Database
Dim qdfTimesQuery As Dao.QueryDef
Dim rstPOTimes As Dao.Recordset 'Temporary Table
Dim rstTimes As Dao.Recordset
Dim lFrequency As Integer
Dim dtStart As Date
Dim dtEnd As Date
Dim sTank As String
Dim dtTempDate As Date
Dim dtFormDate As Date
Set MyDB = CurrentDb
Set qdfTimesQuery = MyDB.QueryDefs("qry_HardData")
qdfTimesQuery.Parameters("[forms]![frm_MainMenu].[dtDate]") = [Forms]![frm_MainMenu].[dtDate]
Set rstTimes = qdfTimesQuery.OpenRecordset("qry_HardData", dbOpenSnapshot)' Datatype Conversion error occurs here
Set rstPOTimes = MyDB.OpenRecordset("tblPOTimes", dbOpenDynaset)
CurrentDb.Execute "delete * from tblPOTimes;", dbFailOnError
Do While Not rstTimes.EOF
dtStart = rstTimes!dtStart
dtEnd = rstTimes!dtExpire
sTank = rstTimes!tankID
lFrequency = 0
dtTempDate = dtStart
Do While dtEnd >= dtTempDate
With rstPOTimes
.AddNew
!dtDate = dtTempDate
!lDuration = lFrequency
!sTankID = sTank
.Update
End With
lFrequency = rstTimes!aValue
dtTempDate = DateAdd("h", lFrequency, dtTempDate)
Loop
rstTimes.MoveNext
Loop
rstTimes.Close
rstPOTimes.Close
Set rstTimes = Nothing
Set rstPOTimes = Nothing
End Sub
Comment