Results 1 to 8 of 8
  1. #1
    Yiannis is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    7

    Two comboboxes - Textbox displays value but I can not type a new value in a form.

    Hi all



    Its been almost 3 weeks having this problem and I am still scratching my head.
    You guess right … I am new to Access … so

    I have two comboboxes,
    Cities coming from a Table S/C (Columns: States and Cities)
    States coming from Table Info (Columns: Cities, Population, Likes, ...)
    Relation one to one – Cities

    And textboxes to display other information (Population, Likes ….)

    The two comboboxes works great together (filtering data) and I can display information in the textboxes (based on the second combo box)
    What I can not do is to change information displayed in a textbox simply by typing a value.
    Example: in a textbox Likes instead of a number displayed e.g 12, I want to change and display to 19.

    Here is the a simple code I am using.

    Code:
     
    Private Sub ComboCities_Click()
                  Population = DLookup("Population", "query2")
                  Likes = DLookup("Likes", "query2")
                  Handover = DLookup("HandOver", "query2")
                 End Sub
     
    Private Sub ComboStates_AfterUpdate()
    ComboCities.Requery
    End Sub


    Any help would be appreciated. Cheers

  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
    The textboxes don't have ControlSource? Is the Locked property set to Yes?
    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
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I have two comboboxes,
    Cities coming from a Table S/C (Columns: States and Cities)
    States coming from Table Info (Columns: Cities, Population, Likes, ...)
    Relation one to one – Cities
    I think you have States and Cities swapped.

    Relation one to one – Cities
    If so, then you don't need two tables...

    One state can have many cities...... True
    One City can be in many states.... False

    Therefore, you have a one to many relationship between states and cities.



    I would have two tables:

    table States
    Fields
    -----
    StateID_PK Autonumber
    StateName Text

    table Cites
    Fields
    -----
    CityID_PK Autonumber
    StateID_FK Long
    CityName Text
    Population Long (or Text)
    Likes Text (???)
    Handover (???)


    The relationship is States.StateID_PK --> Cities.StateID_FK

    The combo boxes would be:

    ComboStates

    ------------
    Row Source:
    SELECT States.StateID_PK, States.StateName
    FROM States
    ORDER BY States.StateName;

    Column count: 2
    Bound Column: 1
    Column Widths: 0"


    ComboCities
    ------------
    Row Source:
    SELECT Cities.CityID_PK, Cities.CityName, Cities.Population, Cities.Likes, Cities.Handover
    FROM Cities
    WHERE (((Cities.StateID_FK)=[forms]![Form8].[comboStates]))
    ORDER BY Cities.CityName;

    Column Count: 5
    Bound Column: 1
    Column Widths: 0"


    The code for comboStates:
    Code:
    Private Sub ComboStates_AfterUpdate()
       ComboCities.Requery
    End Sub
    Code for comboCities:
    Code:
    Private Sub ComboCities_Click()
       Me.Population = Me.comboCities.Column(2)
       Me.Likes = Me.comboCities.Column(3)
       Me.Handover = Me.comboCities.Column(4)
    End Sub
    After selecting a State, then a City, the text boxes are filled in. This is assuming that they are unbound text boxes.


    If you are wanting to edit the City name, Population, Likes, or Handover fields, I would suggest using a mainform/subform arragement.

  4. #4
    Yiannis is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    7
    My Textboxes do not have a control source. They can be displayed either from option 1 or 2:

    1. Me.Population = Me.ComboCities.Column(2)
    2. Population = DLookup("Population", "query2")


    To acquire date for the mentioned TextBoxes I previously used 2 ComboBoxes thus why I used the above options.

    Thanks in advance.

  5. #5
    Yiannis is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    7
    Thanks for your input. I did manage to display information I wanted with your proposed method.
    For editing a textbox, you suggested to use a subform.
    Is there any way that I can do changes on a Form without adding a subform at the bottom of my form?
    Thanks in advance.

  6. #6
    Yiannis is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    7

    No .... it come from a Combo Box

    Quote Originally Posted by June7 View Post
    The textboxes don't have ControlSource? Is the Locked property set to Yes?
    My Textboxes do not have a control source. They can be displayed either from option 1 or 2:


    1. Me.Population = Me.ComboCities.Column(2)
    2. Population = DLookup("Population", "query2")



    To acquire date for the mentioned TextBoxes I previously used 2 ComboBoxes thus why I used the above options.

    Thanks in advance.

  7. #7
    Yiannis is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    7
    Quote Originally Posted by ssanfu View Post
    I think you have States and Cities swapped.


    If so, then you don't need two tables...

    One state can have many cities...... True
    One City can be in many states.... False

    Therefore, you have a one to many relationship between states and cities.



    I would have two tables:

    table States
    Fields
    -----
    StateID_PK Autonumber
    StateName Text

    table Cites
    Fields
    -----
    CityID_PK Autonumber
    StateID_FK Long
    CityName Text
    Population Long (or Text)
    Likes Text (???)
    Handover (???)


    The relationship is States.StateID_PK --> Cities.StateID_FK

    The combo boxes would be:

    ComboStates

    ------------
    Row Source:
    SELECT States.StateID_PK, States.StateName
    FROM States
    ORDER BY States.StateName;

    Column count: 2
    Bound Column: 1
    Column Widths: 0"


    ComboCities
    ------------
    Row Source:
    SELECT Cities.CityID_PK, Cities.CityName, Cities.Population, Cities.Likes, Cities.Handover
    FROM Cities
    WHERE (((Cities.StateID_FK)=[forms]![Form8].[comboStates]))
    ORDER BY Cities.CityName;

    Column Count: 5
    Bound Column: 1
    Column Widths: 0"


    The code for comboStates:
    Code:
    Private Sub ComboStates_AfterUpdate()
       ComboCities.Requery
    End Sub
    Code for comboCities:
    Code:
    Private Sub ComboCities_Click()
       Me.Population = Me.comboCities.Column(2)
       Me.Likes = Me.comboCities.Column(3)
       Me.Handover = Me.comboCities.Column(4)
    End Sub
    After selecting a State, then a City, the text boxes are filled in. This is assuming that they are unbound text boxes.


    If you are wanting to edit the City name, Population, Likes, or Handover fields, I would suggest using a mainform/subform arragement.
    Thanks for your input. I did manage to display information I wanted with your proposed method.
    For editing a textbox, you suggested to use a subform.
    Is there any way that I can do changes on a Form without adding a subform at the bottom of my form?
    Thanks in advance.

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You said the controls Population, Likes and Handover are unbound. You can edit unbound controls, but the changes have no place to be saved. If the controls are bound to a recordset, they could be edited and saved.

    You can write code to save the changes to the unbound controls, but it will be a lot of code to find the correct record to save the changes to.

    I don't understand what you are doing so it is difficult to be more detailed...

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

Similar Threads

  1. Date - Textbox type mismatch 13
    By mdex in forum Programming
    Replies: 7
    Last Post: 01-20-2012, 08:44 AM
  2. Replies: 1
    Last Post: 12-11-2011, 11:48 AM
  3. Replies: 2
    Last Post: 08-06-2011, 12:19 PM
  4. Replies: 3
    Last Post: 06-04-2011, 12:23 PM
  5. Replies: 1
    Last Post: 12-17-2010, 04:25 PM

Tags for this Thread

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