Results 1 to 9 of 9
  1. #1
    NISMOJim is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    273

    Change Row Source

    I have a query (qryParts) with fields Cat (number) and Desc (text). Based on this query is a form called frmParts with the following fields;

    cboCat which has a row source from Table tblLUCat. The bound column, 1, is the CatID number, but the user sees column 2, which is the category (Proto, Production, Office...).

    cboDesc is a description field that I would like to be able to show a dropdown list of possibilities depending on which category is selected in cboCat.



    Here is the code I have tried (a few different ways) but doesn't work. I still get a blank dropdown list for cboDesc.

    Private Sub cboCat_AfterUpdate()

    Dim strSQL As String

    If Me.cboCat = "1" Then
    Me.ProtoID = Me.PartsID
    Me.lblReturn.Visible = True
    More code to make labels etc. visible or not
    ElseIf Me.cboCat = "2" Then
    More code to make labels etc. visible or not
    ElseIf Me.cboCat = "3" Or Me.cboCat = "4" Then
    More code to make labels etc. visible or not
    End If

    strSQL = "SELECT qryParts.Descrip FROM qryParts WHERE qryParts.Cat = " & Me.cboCat
    Me.cboDesc.RowSource = strSQL

    End Sub

    Does someone know how I can fix this?
    Thank You

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    What is the column widths property of that combo? Since you only return one field, the first field must be visible. This will help make sure the SQL is correct:

    http://www.baldyweb.com/ImmediateWindow.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    NISMOJim is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    273
    The cboCat width is 0 (for the CATID number);2 (for the written category).
    The immediate window is showing the correct results;

    SELECT qryParts.Descrip FROM qryParts WHERE qryParts.Cat = 4

    which is how it is logged in qryParts. There are no errors, but the dropdown list is still blank.
    It is ok to use a row source from a query that you are writing to, isn't it? I also tried going straight from the table with the same results.

    I just added a Debug.Print cbo.Desc.RowSource to the code and the immediate window displays
    SELECT tblParts.Descrip FROM tblParts WHERE tblParts.Cat = 4
    This sure looks right to me, but it isn't working.
    Last edited by NISMOJim; 08-31-2012 at 03:00 AM.

  4. #4
    NISMOJim is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    273
    One other thing, when I change the selection in cboCat, cboDesc turns transparent, then it goes back to white when I click on it. Is there a way to keep this from happening? I tried adding Me.cboDesc.BackColor = RGB(250, 250, 250) after the Row Source line, but it didn't work either.

  5. #5
    NISMOJim is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    273
    OK, I got the row source working by changing the column width on cboDesc, thank you. Now I'm just concerned about that box being transparent.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Yes, I meant the second combo. As to the transparent thing, see if it's this one:

    http://allenbrowne.com/Access2007.html#Bugs

    Specifically the one called "Combo becomes transparent". Note that it's lined out because there's a fix.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    GeekInOhio's Avatar
    GeekInOhio is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2012
    Posts
    25
    Quote Originally Posted by NISMOJim View Post
    One other thing, when I change the selection in cboCat, cboDesc turns transparent, then it goes back to white when I click on it. Is there a way to keep this from happening? I tried adding Me.cboDesc.BackColor = RGB(250, 250, 250) after the Row Source line, but it didn't work either.
    On your form select the Detail bar, and in the Property Sheet change the "Alternate Back Color" to anything other than "No Color". Took me forever to solve that annoying little behavior.

    Edit: Whoops... beat to the punch.

  8. #8
    NISMOJim is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    273
    That did the trick. Now, as it turns out, the users want to interface in a different way, so the whole thing was for nothing. Good learning experience for me though, so thank you very much!

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Happy to help. It wasn't for nothing if knowledge was gained!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Change/select record source of subreports
    By TerriLynnG in forum Reports
    Replies: 2
    Last Post: 08-24-2013, 10:18 AM
  2. Replies: 3
    Last Post: 07-20-2012, 11:41 AM
  3. Copying entry form, change control source
    By Bdowns in forum Access
    Replies: 11
    Last Post: 02-06-2012, 05:39 PM
  4. Replies: 2
    Last Post: 11-29-2010, 11:16 AM
  5. change print preview record source
    By alaric01 in forum Reports
    Replies: 10
    Last Post: 10-07-2010, 09:51 AM

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