BrokenBiker
ManicMechanic
- Local time
- Yesterday, 22:26
- Joined
- Mar 22, 2006
- Messages
- 128
Well, I've made a little progress in my attempt to create an append query w/ VBA having a variable destination db. The first portion of code seems to work for now....That is, at least I don't get errors from it.
However, when I run the code I get a syntax error (run-time 3134) in the INSERT INTO statement, but the de-bugger doesn't highlight that portion, instead it highlights the portion in w/ asterisks below. Since that portion depends on the INSERT INTO portion (strSQL = "INSERT INTO...) I'm guessing that's where the problem lies, but I can't seem to fix it.
Here's the code:
____________________
Dim qdf As QueryDef
Dim strSQL As String
Dim ServerPath As Variant
ServerPath = DLookup("[FilePath]", "tblFilePath", "[FilePath] = '" & Me.FilePath & "'")
If IsNull(ServerPath) Then
MsgBox ("Unknown directory.")
Else
strSQL = "INSERT INTO Main Table (Report Number, Rating, Pass " & _
"Fail, Non Rated, Chief Insp Review " & _
"Inspection Type, TEC, Date " & _
"Shift, Time, Inspector Number " & _
"Supervisor Rank, Supervisor Name, Location " & _
"Equipment Type, Equipment SN, Workcenter " & _
"Description, Main Assessee) " & _
"IN '" & ServerPath & "' " & _
"SELECT Report Number, Rating, Pass, Fail, Non Rated " & _
"Chief Insp Review, Inspection Type " & _
"TEC, Date, Shift, Time, Inspector Number " & _
"Supervisor Rank, Supervisor Name, Location, " & _
"Equipment Type, Equipment SN, Workcenter, Description, Main Assessee" & _
"FROM [Main Table] " & _
"WHERE [Main Table].Date <Now()"
Set qdf = CurrentDb.QueryDefs("X")
***qdf.SQL = strSQL***
qdf.Close
End If
____________________________
I've tried to check this against other samples of VBA in hopes of finding an easy mistake like extra spaces, missing quotes (at least where I know they belong...), etc.
In the attachment, open the file TestX.
Thanks.
However, when I run the code I get a syntax error (run-time 3134) in the INSERT INTO statement, but the de-bugger doesn't highlight that portion, instead it highlights the portion in w/ asterisks below. Since that portion depends on the INSERT INTO portion (strSQL = "INSERT INTO...) I'm guessing that's where the problem lies, but I can't seem to fix it.
Here's the code:
____________________
Dim qdf As QueryDef
Dim strSQL As String
Dim ServerPath As Variant
ServerPath = DLookup("[FilePath]", "tblFilePath", "[FilePath] = '" & Me.FilePath & "'")
If IsNull(ServerPath) Then
MsgBox ("Unknown directory.")
Else
strSQL = "INSERT INTO Main Table (Report Number, Rating, Pass " & _
"Fail, Non Rated, Chief Insp Review " & _
"Inspection Type, TEC, Date " & _
"Shift, Time, Inspector Number " & _
"Supervisor Rank, Supervisor Name, Location " & _
"Equipment Type, Equipment SN, Workcenter " & _
"Description, Main Assessee) " & _
"IN '" & ServerPath & "' " & _
"SELECT Report Number, Rating, Pass, Fail, Non Rated " & _
"Chief Insp Review, Inspection Type " & _
"TEC, Date, Shift, Time, Inspector Number " & _
"Supervisor Rank, Supervisor Name, Location, " & _
"Equipment Type, Equipment SN, Workcenter, Description, Main Assessee" & _
"FROM [Main Table] " & _
"WHERE [Main Table].Date <Now()"
Set qdf = CurrentDb.QueryDefs("X")
***qdf.SQL = strSQL***
qdf.Close
End If
____________________________
I've tried to check this against other samples of VBA in hopes of finding an easy mistake like extra spaces, missing quotes (at least where I know they belong...), etc.
In the attachment, open the file TestX.
Thanks.
Attachments
Last edited: