Results 1 to 4 of 4
  1. #1
    Mike70 is offline Novice
    Windows 10 Access 2013
    Join Date
    Jan 2016
    Posts
    11

    Insert mutliple comboxes

    Trying to get data from Access to Excel. This is working fine but...

    With Recordset
    Source = "SELECT Field1, Field2, Field3, Field4, Field5 FROM table1" & _
    "WHERE criteria = " & Worksheets("SomeName").cboBox1 & ";"
    .Open Source:=Source, ActiveConnection:=Connection
    End With

    Range("A5").Offset(1, 0).CopyFromRecordset Recordset

    ...When i´m trying to insert 1 combobox more it´s not working. I tried this:



    With Recordset
    Source = "SELECT Field1, Field2, Field3, Field4, Field5 FROM table1" & _
    "WHERE criteria = " & Worksheets("SomeName").cboBox1 & " AND " & Worksheets("SomeName").cboBox2 & ";"
    .Open Source:=Source, ActiveConnection:=Connection
    End With
    ' Write Recordset
    Range("A5").Offset(1, 0).CopyFromRecordset Recordset

    It's only taking criteria from the first combobox

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,842
    what is Worksheets("SomeName").cboBox2 equal to? You've said criteria=cboBox1

  3. #3
    Mike70 is offline Novice
    Windows 10 Access 2013
    Join Date
    Jan 2016
    Posts
    11
    Forgot that :-). The criteria is in maybe field 6 and 7.

    With Recordset
    Source = "SELECT Field1, Field2, Field3, Field4, Field5 FROM table1" & _
    "WHERE field6 = " & Worksheets("SomeName").cboBox1 & " AND field7 = " & Worksheets("SomeName").cboBox2 & ";"
    .Open Source:=Source, ActiveConnection:=Connection
    End With
    ' Write Recordset
    Range("A5").Offset(1, 0).CopyFromRecordset Recordset

  4. #4
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,842
    so is this now working?

    On the basis your first bit of code works the following won't apply

    if not, you are missing a space between table1 and WHERE

    Since you are using dummy field names, I presume 'recordset' is also a dummy. If not, be aware it is a reserved word and using it can cause unexpected issues

    Finally I presume field6 and field7 are numeric, if not you need to use single quotes

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

Similar Threads

  1. Form with mutliple record source (s0
    By Lou_Reed in forum Access
    Replies: 6
    Last Post: 05-12-2015, 03:13 PM
  2. Replies: 8
    Last Post: 02-18-2015, 01:30 PM
  3. Replies: 4
    Last Post: 10-14-2014, 09:28 AM
  4. Replies: 3
    Last Post: 10-15-2013, 10:54 AM
  5. Creating a query using mutliple tables
    By andrewmo in forum Queries
    Replies: 1
    Last Post: 11-21-2011, 01:11 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