RE: run append query from form
- From: newuser44 <newuser44@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 22 Aug 2008 14:53:02 -0700
This helped for sure... but now I get an syntax error in the FROM clause:
any thoughts?
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
"Klatuu" wrote:
I did not scour the entire statement, but I do see one obvious error. As.
written, you are putting qoutes around the name of the table in the SQL
statement. That is not correct. You only put qoutes around values you want
to insert into a text field.
"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))"
Should be:
"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))"
--
Dave Hargis, Microsoft Access MVP
"newuser44" wrote:
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!
- Follow-Ups:
- RE: run append query from form
- From: Klatuu
- RE: run append query from form
- References:
- run append query from form
- From: newuser44
- RE: run append query from form
- From: Klatuu
- run append query from form
- Prev by Date: RE: run append query from form
- Next by Date: RE: run append query from form
- Previous by thread: RE: run append query from form
- Next by thread: RE: run append query from form
- Index(es):
Relevant Pages
|