+ Reply to Thread
Results 1 to 2 of 2

Connecting Excel to Microsoft access using ADODB.Connection RS.Filter error

  1. #1
    Registered User
    Join Date
    08-24-2016
    Location
    New York
    MS-Off Ver
    2010
    Posts
    1

    Connecting Excel to Microsoft access using ADODB.Connection RS.Filter error

    Hello,

    I'm trying to connect certain parameters in excel to Microsoft access database by a click of an activeX button. I'm getting the following error when trying to execute

    run-time error '3001':
    Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

    The issue is with my rs.filter. Anyone know of a better way to vba code multiple criteria?

    My Code below:

    Private Sub CommandButton2_Click()

    Dim cn As ADODB.Connection, rs As ADODB.Recordset
    Dim sVendor As String, sDocumentDate As String, sInvoice As String, sAmount As String, sLocation As String, sProject As String, sStore As String, sCipfas As String, sLine As String, sCode As String, sDc As String, sPeriod As String
    ' connect to the Access database
    Set cn = New ADODB.Connection
    cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
    "Data Source=C:\Users\rschell\Desktop\Database1.accdb;"
    ' open a recordset
    Set rs = New ADODB.Recordset
    rs.Open "APDatabase", cn, adOpenKeyset, adLockOptimistic, adCmdTable

    Range("J88").Activate ' row J88 contains column headings
    Do While Not IsEmpty(ActiveCell)
    sVendor = ActiveCell.Value
    sDocumentDate = ActiveCell.Offset(0, 1).Value
    sInvoice = ActiveCell.Offset(0, 2).Value
    sAmount = ActiveCell.Offset(0, 3).Value
    sLocation = ActiveCell.Offset(0, 4).Value
    sProject = ActiveCell.Offset(0, 5).Value
    sStore = ActiveCell.Offset(0, 6).Value
    sVendor = ActiveCell.Offset(0, 7).Value
    sCipfas = ActiveCell.Offset(0, 8).Value
    sLine = ActiveCell.Offset(0, 9).Value
    sCode = ActiveCell.Offset(0, 10).Value
    sDc = ActiveCell.Offset(0, 11).Value
    sPeriod = ActiveCell.Offset(0, 12).Value


    rs.Filter = "Vendor='" & sVendor & "' AND Document Date='" & sDocumentDate & "' AND Invoice#='" & sInvoice & "' AND Amount='" & sAmount & "' AND Location='" & sLocation & "' AND Project#='" & sProject & "' AND Store#='" & sStore & "' AND Vendor#='" & sVendor & "' AND CIP/FAS='" & sCipfas & "' AND Line Item='" & sLine & "' AND Code='" & sCode & "' AND DC='" & sDc & "' AND Period='" & sPeriod & "'"
    If rs.EOF Then
    Debug.Print "No existing record - adding new..."
    rs.Filter = ""
    rs.AddNew
    rs("Vendor").Value = sVendor
    rs("Document Date").Value = sDocumentDate
    rs("Invoice#").Value = sInvoice
    rs("Amount").Value = cAmountAsVariant
    rs("Location").Value = sLocation
    rs("Project#").Value = sProject
    rs("Store#").Value = sStore
    rs("Vendor#").Value = sVendor
    rs("CIP/FAS").Value = sCipfas
    rs("Line").Value = sLine
    rs("Code").Value = sCode
    rs("DC").Value = sDc
    rs("Period").Value = sPeriod
    Else
    Debug.Print "Existing record found..."
    End If
    rs("Period").Value = sPeriod
    rs.Update
    Debug.Print "...record update complete."

    ActiveCell.Offset(1, 0).Activate ' next cell down
    Loop
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
    End Sub

  2. #2
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: Connecting Excel to Microsoft access using ADODB.Connection RS.Filter error

    Hi,
    you will have to build your filter a little at at a time to debug it. Start with
    Please Login or Register  to view this content.
    and add a parameter at a time till you find the problem one. I suspect it may be the date if the database field is a date data type.
    you may need to add hashes instead of quotes

    Please Login or Register  to view this content.
    Frob first, tweak later

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Access Query via Excel (ADODB) - no error, but no output!
    By cml111 in forum Access Tables & Databases
    Replies: 3
    Last Post: 04-23-2013, 05:33 AM
  2. ADODB.Connection : Sourcefile + if condition = error
    By vadius in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-08-2013, 03:00 PM
  3. Cannot Use ADODB.Connection to connect to an access database
    By Cardinalbags in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-18-2012, 07:09 PM
  4. System Error in ADODB connection code
    By Jonsocks in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2011, 12:33 PM
  5. Error with using adodb Connection and double quotes
    By JimCo in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 07-23-2010, 11:19 AM
  6. Microsoft Access Table Connection Issues
    By stoneferry in forum Excel General
    Replies: 0
    Last Post: 11-19-2007, 10:16 AM
  7. Connecting to password protected MS Access through Connection String
    By dwijraj in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-20-2007, 02:40 PM
  8. [SOLVED] compile error... ADODB connection
    By ina in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2006, 12:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1