Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 27th, 2007, 02:54 AM
Authorized User
Join Date: Jun 2007
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Importing a Range from Excel

I have this code below that works, and imports the data into the relevant tables. on the line DoCmd.TransferSpreadsheet acLink, , strTempTable, strFilePath, True How can I specify that it import from a range. I have a Range called ImportData on the excel sheet?

Private Sub cmdImport_Click()
    On Error GoTo Err
    Dim cnn As ADODB.Connection
    Dim sQRY As String
    DoCmd.SetWarnings False
    strTempTable = "tblCSATAddressTEMP"
    strFilePath = Me.txtFilePath
    'Check that BusinessType has been selected- quit if not
    If IsNull(Me.cboBusinessType) Or Me.cboBusinessType = "" Then
        MsgBox "You must select a Business Type from the dropdown list", vbExclamation, cApplicationName
        Exit Sub
    End If
    If VBA.Len(strFilePath) <> 0 Then
        'Import the spreadsheet
        DoCmd.TransferSpreadsheet acLink, , strTempTable, strFilePath, True
        Set cnn = New ADODB.Connection
        cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin; " & _
        "Data Source=" & cTables
            'insert new addresses into tblAddress
        sQRY = _
            "INSERT INTO tblCSATAddress" & vbCrLf & _
            "( JobNumber, Address, ProjectID, Project, JobDate, TeamCode, Engineer, Contract, BusinessType )" & vbCrLf & _
            "IN '" & cTables & "' " & vbCrLf & _
            "SELECT" & vbCrLf & _
            "tblCSATAddressTEMP.[No]," & vbCrLf & _
            "tblCSATAddressTEMP.Description," & vbCrLf & _
            "tblCSATAddressTEMP.[Bill-to Customer No]," & vbCrLf & _
            "tblCSATAddressTEMP.[Scheme Code]," & vbCrLf & _
            "tblCSATAddressTEMP.[Planned Start Date]," & vbCrLf & _
            "tblCSATAddressTEMP.[Team Code]," & vbCrLf & _
            "tblFamilyTree.Engineer," & vbCrLf & _
            "tblFamilyTree.Contract," & vbCrLf & _
                "'" & Me.cboBusinessType & "' AS BusinessType" & vbCrLf & _
            "FROM tblCSATAddressTEMP " & vbCrLf & _
            "LEFT JOIN tblFamilyTree ON tblCSATAddressTEMP.[Team Code] = tblFamilyTree.TeamCode"
            CurrentProject.Connection.Execute sQRY
        End If
        DoCmd.DeleteObject acTable, strTempTable
        MsgBox Me.cboBusinessType & " Data has been imported", vbExclamation, cApplicationName
        Set cnn = Nothing
    Exit Sub
    MsgBox VBA.Error$
End Sub

Thanks, Jez

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
importing text file into excel stealthdevil Excel VBA 2 July 10th, 2007 11:28 AM
Importing Excel to Sql Server dowens3rd ADO.NET 0 March 20th, 2007 03:33 PM
Importing text file into excel anamarijaf Excel VBA 4 January 27th, 2007 05:50 AM
Importing from Excel bmains ADO.NET 1 October 9th, 2004 11:44 AM
MS Excel(Importing) S Kamran Access 1 October 29th, 2003 06:55 AM

All times are GMT -4. The time now is 09:48 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.