Results 1 to 3 of 3
  1. #1
    tbassngal is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    27

    Loops

    Can someone help me by adding do while looping code for 3 cboDesc boxes, cboDesc1, cboDesc2, cboDesc3? Seems I am not having luck with anyone helping - is it super difficult for most? While I don't know how to do it, I though it was a fairly simple task - I guess not =( Please help if you can~!!




    Private Sub cboApplication_AfterUpdate()
    Dim sSQL As String
    'MsgBox "The Code is Executing!"

    'clear cboDesc1
    Me.cboDesc1 = Null

    sSQL = "SELECT Desc1 FROM tblApplicationDescription"
    sSQL = sSQL & " WHERE [Application] = '" & Me.[cboApplication] & "' "
    sSQL = sSQL & " ORDER BY Desc1"

    'for debugging
    'Debug.Print sSQL

    Me.cboDesc1.RowSource = sSQL

    'check if txtDesc1 has values
    If IsNull(Me.cboDesc1.ItemData(0)) Then
    Me.cboDesc1.Enabled = False
    Else
    Me.cboDesc1.Enabled = True
    Me.cboDesc1 = Me.cboDesc1.ItemData(0)

    'optional
    Me.cboDesc1.SetFocus
    Me.cboDesc1.Dropdown
    End If

    End Sub

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If your combo boxes are really named cboDesc1, cboDesc2, cboDesc3, then it is easy to do looping.

    What are the row sources for cboDesc2, cboDesc3?

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    What are you attempting to do with your code?

    If you're just trying to see if a recordset has values you can do something like with dcount or, since you already have the SQL statement you can do this:

    Code:
    dim db as database
    dim rst as recordset
    
    set db = currentdb
    set rst = db.openrecordset(ssql)
    
    if rst.recordcount <> 0 then
        <set the enabled property of your combo box to true>
    else
       <set the enabled property of your combo box to false>
    endif
    
    rst.close
    set db = nothing
    You'd just have to fit it into your existing code after you establish the SQL string.

    Or are you trying to build a SQL statement using 1 or more combo boxes as input and are trying to adjust your WHERE statement accordingly? You reference cboDesc2 and cboDesc3 but they appear nowhere in your code.

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

Similar Threads

  1. Loops
    By cksm4 in forum Programming
    Replies: 14
    Last Post: 10-10-2010, 02:10 PM
  2. Beginner - 3 tables in 3 loops
    By dsasorin in forum Database Design
    Replies: 2
    Last Post: 03-20-2010, 06:22 PM
  3. Help with Loops
    By rotorque in forum Access
    Replies: 0
    Last Post: 01-07-2009, 05:06 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