B
bknight
In A97 I'm trying to delete data in a date range. The first step is to
answer a message box.
intMsgBox = MsgBox("Do you wish to delete the only last data?",
vbYesNoCancel, "Delete data")
'Yes--Will Rs.MoveLast and delete data
'Cancel--Ends Sub
'No- Leads to the following steps
If intMsgBox = 7 Then '7 is the value of a No selection
dteStartDate = InputBox("What Is The Begining Date", "Start Date") 'Example
5/1/2009
dteEndDate = InputBox("What Is The Ending Date", "End Date") 'Example
5/22/2009
End If
Now that I have a date range, I build a SQL statement.
strDateRange = "Select * From tblName Where InvDay >=#" & dteStartDate & "#
And InvDay <=#" & dteEndDate & "# Order By DateIndex"
'Results in immediate window
'Select * From tblName Where InvDay >=#5/1/2009# And InvDay <=#5/22/2009#
Order By DateIndex
'This is the range that is to be deleted
'This looks good, BUT
Set Db = CurrentDb
Set Rs = Db.OpenRecordset("'" & strDateRange & "'")' RTE #3078 Cannot find
table...
'In testing I eliminated the end date
strDateRange = "Select * From tblName Where InvDay >=#" & dteStartDate & "#
Order By DateIndex"
'Results in immediate window
'Select * From tblName Where InvDay >=#5/1/2009# Order By DateIndex
Set Db = CurrentDb
Set Rs = Db.OpenRecordset("'" & strDateRange & "'") ' Resulted in the same
error message
'So I made the steps look like this
Set Db = CurrentDb
Set Rs = Db.OpenRecordset("Select * From tblName Where InvDay >=#5/1/2009#
Order By DateIndex")
Everything worked and the rest of the code is easy. Any suggestions?
answer a message box.
intMsgBox = MsgBox("Do you wish to delete the only last data?",
vbYesNoCancel, "Delete data")
'Yes--Will Rs.MoveLast and delete data
'Cancel--Ends Sub
'No- Leads to the following steps
If intMsgBox = 7 Then '7 is the value of a No selection
dteStartDate = InputBox("What Is The Begining Date", "Start Date") 'Example
5/1/2009
dteEndDate = InputBox("What Is The Ending Date", "End Date") 'Example
5/22/2009
End If
Now that I have a date range, I build a SQL statement.
strDateRange = "Select * From tblName Where InvDay >=#" & dteStartDate & "#
And InvDay <=#" & dteEndDate & "# Order By DateIndex"
'Results in immediate window
'Select * From tblName Where InvDay >=#5/1/2009# And InvDay <=#5/22/2009#
Order By DateIndex
'This is the range that is to be deleted
'This looks good, BUT
Set Db = CurrentDb
Set Rs = Db.OpenRecordset("'" & strDateRange & "'")' RTE #3078 Cannot find
table...
'In testing I eliminated the end date
strDateRange = "Select * From tblName Where InvDay >=#" & dteStartDate & "#
Order By DateIndex"
'Results in immediate window
'Select * From tblName Where InvDay >=#5/1/2009# Order By DateIndex
Set Db = CurrentDb
Set Rs = Db.OpenRecordset("'" & strDateRange & "'") ' Resulted in the same
error message
'So I made the steps look like this
Set Db = CurrentDb
Set Rs = Db.OpenRecordset("Select * From tblName Where InvDay >=#5/1/2009#
Order By DateIndex")
Everything worked and the rest of the code is easy. Any suggestions?