Strange SELECT...INTO using vba

M

mpavelko

The below code works fine. In my SELECT INTO statement, if the table
I'm selecting into exists, the error is thrown, I drop the table and
re-run my SELECT INTO statement. This isn't a HUGE problem, but its
bugging me. Notice the three lines of code inside my catch block that
have stars in front of them(i only put the stars there for reference in
this post). To make my code nice and clean, I thought I'd remove those
lines of code and replace all three of them with a single statement:
"Resume". This should drop the table, and since it doesnt exist
anymore, the SELECT INTO should work fine, but it doesn't. If i do
this and run the code, the sequence of events are:
1)Try to execute SELECT INTO statement
2) Error that table exists.
3) Catch Error and drop table
4) Resume at execution of "SELECT INTO" statement.
5) Error thrown that the table DOESN'T EXIST?!?!

Someone please tell me that I'm not crazy and there's a bug in Jet or
DAO!??

On Error GoTo catch
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim GeoplanPath As String

GeoplanPath = Registry.QueryValue(HKEY_LOCAL_MACHINE,
"Software\Geoplan\Paths\", "DB_LOCATION") & "\Geoplan.mdb"
Set db = DBEngine.OpenDatabase(GeoplanPath)

strSQL = "SELECT * INTO Rental_Registrations_Backup FROM
Rental_Registrations"
db.Execute (strSQL)

db.Close
MsgBox "Update Completed!"
Exit Sub
catch:
If Err.Description = "Table 'Rental_Registrations_Backup' already
exists." Then
strSQL = "DROP TABLE Rental_Registrations_Backup;"
db.Execute (strSQL)
* strSQL = "SELECT * INTO Rental_Registrations_Backup FROM
Rental_Registrations"
* db.Execute (strSQL)
* Resume Next
End If

MsgBox Err.Number & " " & Err.Description
Exit Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top