J
John F
These questions pertain to the code below. Thanks in advance.
John
1) Does not work with Sheet1! But works without putting Sheet1 in clause.
With actual spreadsheets I use, there are several sheets, so need to specify
which sheet
2) Requires first row in range to have field names corresponding to fields
in Access table. Can I eliminate that requirement and have columns read into
the fields listed after the INSERT INTO?
3) Instead of having path and file name either hardcoded, or included via a
string parameter entered by user, can I call a function to browse and return
path and filename in a string?
4) Get error when rsTemp.Close not commented indicating already closed.
Confused as I did not close rsTemp.
5) Surprised that it will work with adOpenForwardOnly, adLockReadOnly in
the rsTemp.Open statement. Normally I use adOpenDynamic, adLockOptimistic
for recordsets that I write to.
Private Sub cmdImport_Click()
Dim strSQL As String
Dim rsTemp As New ADODB.Recordset
strSQL = "INSERT INTO tblTableInput (txtField1, txtField2,
lngzField3, lngzField4) " _
& "SELECT * FROM Sheet1!C3:Sheet1!F6 IN " &
"""c:\test\testinput.xls"" " & _
"""Excel 5.0;"""
rsTemp.Open strSQL, CurrentProject.Connection, adOpenForwardOnly,
adLockReadOnly
'rsTemp.Close
'Set rsTemp = Nothing
End Sub
John
1) Does not work with Sheet1! But works without putting Sheet1 in clause.
With actual spreadsheets I use, there are several sheets, so need to specify
which sheet
2) Requires first row in range to have field names corresponding to fields
in Access table. Can I eliminate that requirement and have columns read into
the fields listed after the INSERT INTO?
3) Instead of having path and file name either hardcoded, or included via a
string parameter entered by user, can I call a function to browse and return
path and filename in a string?
4) Get error when rsTemp.Close not commented indicating already closed.
Confused as I did not close rsTemp.
5) Surprised that it will work with adOpenForwardOnly, adLockReadOnly in
the rsTemp.Open statement. Normally I use adOpenDynamic, adLockOptimistic
for recordsets that I write to.
Private Sub cmdImport_Click()
Dim strSQL As String
Dim rsTemp As New ADODB.Recordset
strSQL = "INSERT INTO tblTableInput (txtField1, txtField2,
lngzField3, lngzField4) " _
& "SELECT * FROM Sheet1!C3:Sheet1!F6 IN " &
"""c:\test\testinput.xls"" " & _
"""Excel 5.0;"""
rsTemp.Open strSQL, CurrentProject.Connection, adOpenForwardOnly,
adLockReadOnly
'rsTemp.Close
'Set rsTemp = Nothing
End Sub