Results 1 to 8 of 8
  1. #1
    AmanKaur123 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2017
    Posts
    47

    Multicolumn Combobox property issue


    Hi All

    When I try to retrieve the value from access table and store it in multicolumn combo box then the rowsource property works fine and populate the combobox with the data.

    but in actual I want to display the value in the combobox so I don't have to select it from the combobox and it appears automatically.
    Also I can't use textbox to replace combobox.

    The single column combobox works absolutely fine as below:
    Code:
    Me.CboOption = rs.Fields("Dept")
    What change will I need to make in the following code to achieve what I want.
    Code:
    Me.CboBDForms.RowSource = "SELECT * FROM tblTC_Type WHERE (((tblTC_Type.[role])=[cborole].[value] and tblTC_Type.[Dept]='BD' and ID=" & rs.Fields("tblTC_Type.ID") & "));"
    ANy help will be much appreciated.

    Thanks

  2. #2
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,798
    the first works because you're dealing with a single value. In the second, you're returning anywhere from 1 to 255 fields (by using the *) and as many records as there are that match the criteria. You'd need to return only one record, and set the column value to match the position from your recordset field. Something like
    Code:
    With Me.CboOption
     .Column(0) = rs.Fields("Dept")
     .Column(1) = rs.Fields("Shift")
     .Column(2) = rs.Fields("Planner")
    End With
    This assumes that you don't want the combo to have more than one row, as your post suggests, which is very odd. Not sure why you don't just use textboxes. Note that you usually don't need to refer to the value property of a control. Most often, it is the default. Note also that combo columns and rows are zero based.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    AmanKaur123 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2017
    Posts
    47
    Thanks Micron for the reply but I am getting Error message "Object required" . The combobox named cboBDForms exist and is 2 column combobox.
    Code:
    strsql = "SELECT ID,[SignOff_Form] FROM tblTC_Type WHERE role='" & Me.[cboRole] & "' and Dept='" & Me.CboOption & "' and ID=" & Me.txtDummy & ""
    Set rs = CurrentDb.OpenRecordset(strsql)
    If Me.CboOption = "BD" Then
    Me.lblBDForms.Visible = True
    Me.CboBDForms.Visible = True
    
    Me.CboBDForms.Column(0) = rs.Fields(0)  'Object required error message
    Me.CboBDForms.Column(1) = rs.Fields(1)   'Object required error message

  4. #4
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    Shouldn't you be referencing the field names in rs.Fields(), like you exhibited in your first post?

  5. #5
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,798
    rs.names or numbers won't matter unless you move the results around via sql edits.
    Without seeing your module, my guess is that you don't have Option Explicit at the top of every module (it is a vb editor property setting) and you have not declared your recordset object name as rs, but as something else - maybe rst. To test that guess, insert Msgbox rs.fields(0) before the red line. Hopefully you will get the same error after eliminating the combo from the equation.

    Those who don't set/check the 'require variable declaration' option get what they deserve - or so I'm told.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    AmanKaur123 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2017
    Posts
    47
    Micron, All the variables are already defined and I have already used Option Explicit. When I try to display the values of recordset variables then it works fine but when I try to store in combobox then the error message "Object required" comes up. The combobox named "CboBDForms" has the following properties set:
    Column count = 2
    Column Widths =0cm;2cm

    Code:
    strsql1 = "SELECT ID,[SignOff_Form] FROM tblTC_Type WHERE role='" & Me.[cboRole] & "' and Dept='" & Me.CboOption & "' and ID=" & Me.txtDummy & ""
    Set rs = CurrentDb.OpenRecordset(strsql1)
    If Me.CboOption = "BD" Then
    Me.lblBDForms.Visible = True
    Me.CboBDForms.Visible = True
    MsgBox rs.Fields(0)
    MsgBox rs.Fields(1)
    'Me.CboBDForms.RowSource = "SELECT ID,[SignOff_Form] FROM tblTC_Type WHERE role='" & Me.[cboRole] & "' and tblTC_Type.[Dept]='BD' and ID=" & Me.txtDummy & ";"
    With CboBDForms
        .Column(0) = rs.Fields(0)
        .Column(1) = rs.Fields(1)
    End With

  7. #7
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    try cboBDForms.setfocus before the "with" line might help

    But surely you cant set the value of a combobox

  8. #8
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,798
    In your first code sample, you omitted that the combo might have a rowsource, which AFAIK, means you cannot alter the values returned to it. If it even could work, you'd have to tell it what row to place values. You'll have to explain why you're trying to do this, since a combo is meant for displaying values as per the list rows and columns that are returned to it. Why you are trying to inject values from a recordset is a puzzle. Like andy49 suggests, I doubt you can do this, nor should you want to.

    The present error would be because you have gone too far down into the reference, meaning you're trying to work with the combo without identifying the parent form. If you look at what I posted versus what you did, they are not the same-
    With Me.CboOption
    With CboBDForms
    If you fix that, I expect you'll generate an error related to Property Get and Property Let anyway, so I suggest you explain what the process is (related to this form) and what you want to have happen. I think there is a problem with your approach.

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

Similar Threads

  1. Replies: 1
    Last Post: 09-22-2016, 05:02 AM
  2. multicolumn Combobox
    By SSUTTON in forum Forms
    Replies: 5
    Last Post: 04-02-2015, 02:33 PM
  3. Using Tag Property of combobox controls
    By User777 in forum Access
    Replies: 4
    Last Post: 09-18-2013, 01:34 PM
  4. Design Issue: Custom Property?
    By Stan Denman in forum Database Design
    Replies: 2
    Last Post: 03-30-2012, 11:11 AM
  5. Property Sheet issue desperate!!
    By pavarga in forum Reports
    Replies: 5
    Last Post: 07-23-2009, 08:18 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