Code not working (1 Viewer)

Drunkenneo

Registered User.
Local time
Tomorrow, 04:43
Joined
Jun 4, 2013
Messages
192
Hi i have written a query:

Dim fdate As Date
Dim tdate As Date

On Error GoTo Err_cmd_Details_exp_Click

frdate = from_date.Value
todate = To_date.Value
DoCmd.DeleteObject acQuery, "qryTemp1"
If (from_date.Value <> "") And (To_date.Value <> "") Then
'Me.Form.RecordSource = "select * from Master where Created_Date between #" & fdate & "# And #" & tdate & "# order by Checked_Date desc"
Me.RecordSource = "select * from Master_Log where Date_processed between #" & frdate & "# And #" & todate & "# order by Date_processed desc"
CurrentDb.CreateQueryDef "qryTemp1", Me.RecordSource
'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryTemp1", "Z:\Intel\Redemptions\APAC\Yebhi.com\Master_Report.xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryTemp1", "E:\Yebhi\Master_Report.xls"
'DoCmd.DeleteObject acQuery, "qryTemp"
MsgBox "file Exported Z:\Intel\Redemptions\APAC\Yebhi.com\Master_Report.xls"
End If

which is deleting the qrytmp1 but not writing again.
Please Solve
 
Are you sure it is going into the if statement block?
Put a break point into you code, and step through it.
 
yes its going in the if statement and deleting the qrytemp1
 
yes its going in the if statement and deleting the qrytemp1
Sorry - but you are deleting qrytemp1 before the if statement.
I thing I see is you are declaring 2 variable fdate and tdate, but you are not declaring frdate, todate.
Code:
Dim [B][COLOR=Red]fdate[/COLOR][/B] As Date
Dim [B][COLOR=Red]tdate[/COLOR][/B] As Date

On Error GoTo Err_cmd_Details_exp_Click

[B][COLOR=Red]frdate[/COLOR][/B] = from_date.Value
[B][COLOR=Red]todate[/COLOR][/B] = To_date.Value
...
...
Me.RecordSource = "select * from Master_Log where Date_processed between  #" & [B][COLOR=Red]frdate[/COLOR][/B] & "#  And  #" & [B][COLOR=Red]todate[/COLOR][/B] & "# order by  Date_processed desc"
 
Use Option Explicit in your modules to prevent such mis-spellings.
 

Users who are viewing this thread

Back
Top Bottom