Results 1 to 3 of 3
  1. #1
    cmb is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    11

    Populating a combo box from a query - Run-time Error 3016

    Hi There,



    I really hope someone can help me with this. I am trying to populate a combo box (cboVenderID) with one of the two queries below. But "Set rs = db.OpenRecordset(strSQL)" causes a Run-time Error '3016': To few parameters. Expected 1.

    I am new to VBA and SQL so any help would be really appreciated!


    Dim strSQL As String
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim intVenNum As Integer

    intVenNum = Me.cboVenderTypeID

    If intVenNum = 4 Then

    strSQL = "SELECT tblVenders.VenderID, tblVenders.VenderFullName, tblVenders.VenderTypeID " & _
    "FROM tblNodes " & _
    "INNER JOIN tblVenders " & _
    "ON tblNodes.NodeID = tblVenders.NodeID " & _
    "WHERE (((tblVenders.VenderTypeID)=[Form]![cboVenderTypeID])) " & _
    "ORDER BY tblVenders.VenderFullName;"

    Else

    strSQL = "SELECT tblVenders.VenderID, tblVenders.VenderFullName, tblVenders.VenderTypeID, tblNodes.NodeID " & _
    "FROM tblNodes " & _
    "INNER JOIN tblVenders " & _
    "ON tblNodes.NodeID = tblVenders.NodeID " & _
    "WHERE (((tblVenders.VenderTypeID)=[Form]![cboVenderTypeID]) " & _
    "AND ((tblNodes.NodeID)=[Forms]![frmOrdersWithSites]![OrderNode])) " & _
    "ORDER BY tblVenders.VenderFullName;"

    End If

    Set db = CurrentDb()
    Set rs = db.OpenRecordset(strSQL)

    Me!cboVenderID.RowSource = rs
    DoCmd.RunCommand acCmdSaveRecord
    Me!cboVenderID.Requery

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Can't set a combobox list with a recordset object. What you need to do is set the combobox RowSource property with an SQL statement.

    If Me.cboVenderTypeID = 4 Then
    Me.cboVenderID.RowSource = the first SQL statement
    Else
    Me.cboVendorID.RowSource = the second SQL statement
    End If

    Also, variables should not be enclosed in quote marks - concatenate variables. Reference to form controls/fields is a variable. So probably need to concatenate the references to form:

    "WHERE tblVenders.VenderTypeID=" & [Form]![cboVenderTypeID] & _
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    cmb is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    11
    Thanks June7 your help allowed me to get it working!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  2. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  3. Replies: 2
    Last Post: 11-21-2012, 12:11 AM
  4. Replies: 13
    Last Post: 10-25-2012, 06:15 PM
  5. Replies: 6
    Last Post: 05-30-2012, 12:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums