Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 37
  1. #16
    stmoong is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    Sometimes when you stare too hard, you'll miss it.



    [tblStates].StateID=" & Me.cmbCities

    should be

    [tblStates].CityID=" & Me.cmbCities

  2. #17
    JFo is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    393
    Perfect, thanks very much... I am silly

    it should actually be [tblCities].CityID=" & Me.cmbCities

    but that was the problem, thanks for all your help


    Now for the slightly more difficult second part of my question trying to start the combos in display mode from the values from the main form (edit mode).

    I will have a go at this now with the code I have and mark this thread as solved if I can figure it out

    Cheers again

  3. #18
    stmoong is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    You're welcome.

  4. #19
    JFo is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    393
    Yes I have struggled on and on for many hours and I cannot do this from form to form, this is the main thing I want it to do, I am lost

    When a form opens how can it be so difficult (for me anyway) to display the value without having to select it from a list?

  5. #20
    stmoong is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    Just set the values of the controls in the Form Load event.

  6. #21
    JFo is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    393
    That is what I have tried to do many times however it does not work for me using


    Private Sub Form_Load()

    With Me.cmbCities
    .RowSource = _
    "SELECT [tblCities].CityID, [tblCities].CityName, [tblContact].CityID FROM tblCities" & _
    " RIGHT JOIN tblContact ON tblContact.CityID=[tblCities].CityID" & _
    " WHERE [tblCities].CityID =" & Forms!frmMainMenu![cmbClientsContact] & " ORDER BY [tblCities].CityName;"
    .Requery
    .Value = .ItemData(0)
    .Visible = True
    End With
    End Sub

  7. #22
    JFo is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    393
    The value works to be selected from list if i use

    SELECT tblCities.CityID, tblCities.CityName, tblCities.Postcode, tblCities.StateID FROM tblCities WHERE (((tblCities.[CityID])=[Forms]![frmContact]![CityID] OR [Forms]![frmContact]![CityID] Is Null)) ORDER BY tblCities.CityName;

    in row source otherwise I am stuck on this one


    Thanks

  8. #23
    stmoong is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    Quote Originally Posted by JFo View Post
    That is what I have tried to do many times however it does not work for me using


    Private Sub Form_Load()

    With Me.cmbCities
    .RowSource = _
    "SELECT [tblCities].CityID, [tblCities].CityName, [tblContact].CityID FROM tblCities" & _
    " RIGHT JOIN tblContact ON tblContact.CityID=[tblCities].CityID" & _
    " WHERE [tblCities].CityID =" & Forms!frmMainMenu![cmbClientsContact] & " ORDER BY [tblCities].CityName;"
    .Requery
    .Value = .ItemData(0)
    .Visible = True
    End With
    End Sub

    Is the control name highlighted correct?

    If it is correct, then you will need to set the value for [cmbClientsContact] first before setting this [cmbCities] control.

  9. #24
    JFo is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    393
    Yes the name is correct here is the SQL that populates this combo box in the main form

    With Me.cmbClientsContact
    .RowSource = _
    "SELECT [tblContact].ContactID, [tblContact].ContactName, [tblContact].CityID, [tblContact].ContactSurName FROM tblClients" & _
    " RIGHT JOIN tblContact ON tblClients.ClientID=[tblContact].ClientID" & _
    " WHERE [tblContact].ClientID=" & Me.cmbClients & " ORDER BY [tblContact].ContactName;"
    .Requery
    .Value = .ItemData(12)
    .Visible = True
    End With

    From this selection that is what populates entire contact form and all text boxes work it's just the combos don't display

    Thanks again

  10. #25
    stmoong is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    Change this ".Value = .ItemData(12)" to ".Value = .ItemData(0)" to select the first value. Why did you select the 11th row?

    Forms!frmMainMenu![cmbClientsContact] change to Me.cmbClientsContact for consistency (unless I misunderstood that this control is on another form?)

  11. #26
    JFo is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    393
    Change this ".Value = .ItemData(12)" to ".Value = .ItemData(0)" to select the first value. Why did you select the 11th row? Sorry yes this was 12 because I was lazy deleting my table

    Forms!frmMainMenu![cmbClientsContact] change to Me.cmbClientsContact for consistency (unless I misunderstood that this control is on another form?) yes it is on another form

    Basically on main form I select the contact name from combo box and click command button to edit client and it opens contact form that is populated with all contact details. This works for everything except I want to display the combo result without selecting it from list

  12. #27
    stmoong is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    Oh, now it's clearer.

    I haven't tested this. The query will give you a list of city. Then you just need to set the value to the same as the one from frmMainMenu.

    With Me.cmbCities
    .RowSource = _
    "SELECT [tblCities].CityID, [tblCities].CityName, [tblContact].CityID FROM tblCities" & _
    " RIGHT JOIN tblContact ON tblContact.CityID=[tblCities].CityID" & _
    " ORDER BY [tblCities].CityName;"
    .Requery
    .Value = Forms!frmMainMenu![cmbClientsContact]
    .Visible = True
    End With
    Both the cmbClientsContact and cmbCities should be bounded to CityID for it to work, otherwise, you need to reference the correct column to get the matching data.

  13. #28
    JFo is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    393
    Thanks for your reply I was going to reply and say that your method didn't work however I have broken my own design which may be the problem as it was working and can't fix it

    trying to open in edit mode the command button I had something like this

    Private Sub cmdEditClientsContact_Click()
    Dim stLinkCriteria As String
    Dim SID As Integer

    stLinkCriteria = "Me![ContactID]=' " & Forms![frmMainMenu]![cmbClientsContact]

    DoCmd.OpenForm "frmContact", acNormal, , , acFormEdit, , stLinkCriteria


    but now this is delivering same person every time independent of what is selected in the combo

  14. #29
    JFo is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    393
    It is selecting first entry in table every time to edit, regardless

  15. #30
    stmoong is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    The only thing I can think of is you need to set .Value to be what was selected in the main form. Previously, it was selecting the first item via .ItemData(0)

    Maybe better if you could post a database up.

Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Display 2 Columns in Combo Box?
    By 10 Gauge in forum Forms
    Replies: 3
    Last Post: 04-12-2011, 10:24 AM
  2. Combo box dafault display value !!!
    By Kazim in forum Access
    Replies: 1
    Last Post: 02-28-2011, 09:31 AM
  3. Replies: 7
    Last Post: 02-07-2011, 10:11 PM
  4. Combo Box List display HELP!
    By ehabo in forum Access
    Replies: 11
    Last Post: 01-04-2011, 12:55 PM
  5. Combo Box Display
    By ssaucedo in forum Reports
    Replies: 17
    Last Post: 08-10-2009, 05:52 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