Results 1 to 8 of 8
  1. #1
    Jon-G is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2011
    Posts
    15

    Question Combo Box Query Lookup ListIndex Woes

    HI guys, Im having a problem with my Contacts lookup combo box.

    What I am trying to achieve is to have the combo jump to the new contact after it has been entered into the table.

    The combo is on a form that is linked to the Plots table, and its control source is the ClienteID field (the correct relationships are in place). The Row Source populates the list via the following query:



    Code:
    SELECT [qryClienteInfo].FullName, [qryClienteInfo].Saludo, [qryClienteInfo].Apellido, [qryClienteInfo].Nombre, [qryClienteInfo].Telčfono, [qryClienteInfo].Email, [qryClienteInfo].ClienteID FROM qryClienteInfo ORDER BY [Apellido], [Nombre];
    This is working correctly, and I have the column widths set just to show the FullName field (which is the first name and surname concatenated together in the qryClienteInfo.

    The new user is added via a pop-up form, and I have the following DLookup in the verify/append routine which finds the ClienteID value which has been assigned to the new record. This is also returning the correct ClienteID

    Code:
    Result = DLookup("[ClienteID]", "tblClientes", "[Nombre] = '" & ebNombre.Value & "' And [Apellido] = '" & ebApellido.Value & "' And [Dirreción] = '" & ebDirreción.Value)
    What I would then like to do is find this record in the combos list and have the combo jump to it, but I dont know how I can get back the position of the record with this ClienteID from the query to set the ListIndex option correctly. Note that the order of items returned from the query is sorted alphabetically on surname, so I cant just jump to the last record, as the new item is sorted into the results after I requery the combo (and thus re-run the query)

    Any advice would be greatly appreciated

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    There is no need to 'jump to' the item in the combobox list. The combobox should be requeried so that the new ClientID is in the list then simply set the combobox value to that ClientID.

    Is this combobox set as multi-column? Is the ClientID field hidden by setting width to 0?
    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
    Jon-G is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2011
    Posts
    15
    Quote Originally Posted by June7 View Post
    There is no need to 'jump to' the item in the combobox list. The combobox should be requeried so that the new ClientID is in the list then simply set the combobox value to that ClientID.

    Is this combobox set as multi-column? Is the ClientID field hidden by setting width to 0?

    Yes this is exactly what I need. By jumped I meant set to. Yes the cb is multi column and the ClienteID field is persent but just not displayed because I've hidden it with the columnwidths settings.

    How do I set the cb to the row I need?

  4. #4
    Jon-G is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2011
    Posts
    15
    bummmmmmmmp

  5. #5
    Jon-G is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2011
    Posts
    15
    Can anybody else shed any light? Ideally a code sample would be most beneficial

    TIA

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Frequent bumping in a short period is considered bad form.

    Couple ways you can do this. Where is the code that requeries the combobox? Is the combobox LimitToList property set to Yes? This is one way I pass value from a popup.
    Code:
    DoCmd.OpenForm "DialogGetDate", , , , , acDialog, "Report" 
    If CurrentProject.AllForms("DialogGetDate").IsLoaded Then
        Me.tbxDate = Form_DialogGetDate.tbxDate
        DoCmd.Close acForm, "DialogGetDate"
    End If
    Here is another:
    Code:
    Private Sub cbxStateNum_NotInList(NewData As String, Response As Integer)
    If MsgBox("State Number not in database.  Add new project record?", vbYesNo + vbQuestion, "NoRecord") = vbYes Then
        If MsgBox("Do you really want to add a new project record?", vbYesNo, "ConfirmAddNewProject") = vbYes Then
            DoCmd.OpenForm "AddEditProject", acNormal, , , , acDialog, NewData
            Me.cbxStateNum = NewData
            Me.lbxProjects.Requery
            Me.tbxDateSampled.SetFocus
        Else
            Me.cbxStateNum = Null
            Me.cbxStateNum.SetFocus
        End If
    Else
        Me.cbxStateNum = Null
        Me.cbxStateNum.SetFocus
    End If
    Response = acDataErrContinue
    Me.cbxStateNum.Requery
    End Sub
    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.

  7. #7
    Jon-G is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2011
    Posts
    15
    ok point taken, but I was stuck at this point!

    Here is what I have now come up with which is working as expected. This is in the verify/exit function of the new client entry form. Any comments on the efficiency of doing it like this well received:

    Code:
    'Get the details of our new client
                Dim lngClienteID As Long
                Dim sQuery As String
                
                'set up the query for dlookup
                sQuery = "[Nombre] = '" & ebNombre.Value & "' And [Apellido] = '" & ebApellido.Value & "' And [Dirreción] = '" & ebDirreción.Value & "'"
                
                'Close the form and save the new contact
                DoCmd.Close acForm, "frmClientes", acSaveYes
                
                'Get the ID of the new contact
                lngClienteID = Nz(DLookup("[ClienteID]", "tblClientes", sQuery))
                
                'Set the Clientes cb to our new client
                Forms!frmLote.cbClienteNombre.Requery
                
                Dim intX As Integer
                
                If lngClienteID < 1 Then Exit Sub
                
            
                    For intX = 0 To Forms!frmLote.cbClienteNombre.ListCount - 1
                    
                    If Forms!frmLote.cbClienteNombre.Column(5, intX) = lngClienteID Then
                    
                        'If entry found, set combobox to new entry
                        Forms!frmLote.cbClienteNombre.SetFocus
                        Forms!frmLote.cbClienteNombre.ListIndex = intX
                    Exit For
                End If
                Next

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    I believe the acSaveYes argument pertains to saving an edited design, not with saving a record, so it doesn't do anything (I have never used it). A record is automatically committed to table when form closes.

    Otherwise, code seems as good as any. Congratulations!
    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.

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

Similar Threads

  1. error message woes
    By ggs in forum Forms
    Replies: 4
    Last Post: 05-29-2011, 04:03 AM
  2. lookup query and display in combo box?
    By Jackie in forum Programming
    Replies: 6
    Last Post: 04-05-2011, 08:46 PM
  3. Combo Lookup
    By b123 in forum Forms
    Replies: 1
    Last Post: 02-24-2011, 11:24 AM
  4. Combo box lookup confusion
    By redpenner in forum Forms
    Replies: 5
    Last Post: 08-19-2010, 08:45 PM
  5. Combo box woes...
    By jonbonazza in forum Forms
    Replies: 3
    Last Post: 06-21-2010, 11:34 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