N
newuser44
I have a table to which I need to append data on a monthly basis from an
excel table that I import manually into Access. What I would like to do is
select the table on a form, click a button, and have only new records
appended to the main data table. I pretty much have all of this figured out,
but I can't seem to combine setting the table name in VBA, so that the SQL
insert query runs on the most current table I selected on the form.
Here is the VBA code I have been using:
Private Sub Command1_Click()
Dim strSQL As String
Dim tbl_new As String
tbl_new = Me![Combo2]
strSQL = "INSERT INTO Table_Patient ( DOB, PATIENT_SEX, PATIENT_FIRST_NAME,
PATIENT_LAST_NAME, PATIENT_CITY, PATIENT_STATE_2, MRN ) " & _
"SELECT DISTINCT
DateSerial(Right([PATIENT_DATE_OF_BIRTH],4),IIf((Len([PATIENT_DATE_OF_BIRTH])=8),Mid([PATIENT_DATE_OF_BIRTH],1,2),Left([PATIENT_DATE_OF_BIRTH],1)),IIf((Len([PATIENT_DATE_OF_BIRTH])=8),Mid([PATIENT_DATE_OF_BIRTH],3,2),Mid([PATIENT_DATE_OF_BIRTH],2,2)))
AS DOB, '" & tbl_new & "'.PATIENT_SEX, '" & tbl_new & "'.PATIENT_FIRST_NAME,
'" & tbl_new & "'.PATIENT_LAST_NAME, '" & tbl_new & "'.PATIENT_CITY, '" &
tbl_new & "'.PATIENT_STATE_2, '" & tbl_new & "'.MRN " & _
"FROM '" & tbl_new & "' " & _
"LEFT JOIN Table_Patient ON ['" & tbl_new & "'].MRN = Table_Patient.MRN " & _
"WHERE ((('" & tbl_new & "'.PATIENT_SEX) Is Not Null) And
((Table_Patient.MRN) Is Null))"
CurrentDb.Execute strSQL
End Sub
Here is the error I get:
run time error 3450
syntax error in query. incomplete query clause.
Can anybody help with this?
thanks!
excel table that I import manually into Access. What I would like to do is
select the table on a form, click a button, and have only new records
appended to the main data table. I pretty much have all of this figured out,
but I can't seem to combine setting the table name in VBA, so that the SQL
insert query runs on the most current table I selected on the form.
Here is the VBA code I have been using:
Private Sub Command1_Click()
Dim strSQL As String
Dim tbl_new As String
tbl_new = Me![Combo2]
strSQL = "INSERT INTO Table_Patient ( DOB, PATIENT_SEX, PATIENT_FIRST_NAME,
PATIENT_LAST_NAME, PATIENT_CITY, PATIENT_STATE_2, MRN ) " & _
"SELECT DISTINCT
DateSerial(Right([PATIENT_DATE_OF_BIRTH],4),IIf((Len([PATIENT_DATE_OF_BIRTH])=8),Mid([PATIENT_DATE_OF_BIRTH],1,2),Left([PATIENT_DATE_OF_BIRTH],1)),IIf((Len([PATIENT_DATE_OF_BIRTH])=8),Mid([PATIENT_DATE_OF_BIRTH],3,2),Mid([PATIENT_DATE_OF_BIRTH],2,2)))
AS DOB, '" & tbl_new & "'.PATIENT_SEX, '" & tbl_new & "'.PATIENT_FIRST_NAME,
'" & tbl_new & "'.PATIENT_LAST_NAME, '" & tbl_new & "'.PATIENT_CITY, '" &
tbl_new & "'.PATIENT_STATE_2, '" & tbl_new & "'.MRN " & _
"FROM '" & tbl_new & "' " & _
"LEFT JOIN Table_Patient ON ['" & tbl_new & "'].MRN = Table_Patient.MRN " & _
"WHERE ((('" & tbl_new & "'.PATIENT_SEX) Is Not Null) And
((Table_Patient.MRN) Is Null))"
CurrentDb.Execute strSQL
End Sub
Here is the error I get:
run time error 3450
syntax error in query. incomplete query clause.
Can anybody help with this?
thanks!