How would I modify the code at the bottom (BOLDED) to accomplish the following excel import statements? I need to import specific cells from the datasheet.
above code credited to cmmrfrds
Thanx,
Joe
Code:
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97, "CurrentUIC", filenameimp, True, [b]"PRTEdit!a1:a2"[/b]
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97, "ImportAllData", filenameimp, True, [b]"PRTEdit!a4:n"[/b]
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97, "ImportBCAData", Finalsaveb, True, [b]"BCEdit!a4:q"[/b]
Code:
Public Function UpdateExcel()
On Error GoTo ErrHandler
Dim cn As New Connection, cn2 As New Connection
Dim rs As New Recordset, rs2 As New Recordset
Dim connString As String, connString2 As String
Dim sql1 As String, sql2 As String
[b]connString = "provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\ATestDir\myTest.xls;" & _
"Extended Properties=""Excel8.0;HDR=Yes;"";"[/b]
cn.ConnectionString = connString
cn.Open connString
''cn2.Open connString
Set rs.ActiveConnection = cn
'-- sheet name = newcustomers
sql1 = "select * from newcustomers"
rs.Open sql1, cn, adOpenForwardOnly, adLockReadOnly
If Not (rs.EOF = True) Then
Debug.Print "field value = "; rs.Fields(0).Value
End If
'--- you could insert code to loop and write text file here.
Exit Function
ErrHandler:
Dim er As ADODB.Error
Debug.Print " In Error Handler "; Err.description
For Each er In cn.Errors
Debug.Print "err num = "; Err.Number
Debug.Print "err desc = "; Err.description
Debug.Print "err source = "; Err.Source
Next
End Function
Thanx,
Joe