as self taught beginner, there is a control on form to change date that is textbox "txtstartda te" and "txtenddate ". however when btnnameexport click popup error 3021 showed - no current record.
and also i want to know below line with pointing arrow.
my objective is to create tempquery which filter by date using 2 control on form......tempq uery created then export process run then the tempquery deleted
and im stuck at line ".MoveFirst "
and also i want to know below line with pointing arrow.
my objective is to create tempquery which filter by date using 2 control on form......tempq uery created then export process run then the tempquery deleted
and im stuck at line ".MoveFirst "
Code:
Function Export_To_Excel()
Dim dbs As Database
Dim rst_WrkShtName
Dim WrkShtName As String
Dim qdfTemp As QueryDef
DoCmd.SetWarnings False
Set dbs = CurrentDb
'-- Use this query to find a field to be used as names for the worksheets
Set rst_WrkShtName = dbs.OpenRecordset("SELECT * FROM [qryrcptiddata] WHERE REGDATE Between '*" & txtstartdate & "*' And '*" & txtenddate & "*';")
With rst_WrkShtName
.MoveFirst
Do While Not rst_WrkShtName.EOF
WrkShtName = (rst_WrkShtName("??")) <---- [I]what should i put here.[/I]
With dbs
' Creates a query named as the current Tb_Fieldname, query produces results for each worksheet
' The worksheet is created with the same name as the Query
Set qdfTemp = .CreateQueryDef(WrkShtName, "SELECT * FROM [qryrcptiddata] WHERE * = '" & WrkShtName & "';")
' Transfers this query to a spreadsheet named as WrkShtName in the same file
DoCmd.TransferSpreadsheet 1, 8, WrkShtName, "C:\temp\<Excel_Filename.xls>", True
' Deletes the query after exporting to excel
.QueryDefs.Delete WrkShtName
Comment