Results 1 to 9 of 9
  1. #1
    edson is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2014
    Posts
    57

    Forcing a value on a combo box by clicking a form button.

    Good morning you all. I need help on the following matter: I use a Frm1 which updates my Tbl1. By clicking on this Bt1 of the Frm1 the record is duplicated on purpose having enabled and disabled fields. While Frm1 shows the duplicated record (so it is open) I can change it and save it as needed. However the Frm1 loads having an enabled Cbo1 which normally allows the regular user to pick any value A,B,C or D.
    What I would like to have is a line code under the Bt1 click event able to set the value "D" on the duplicated record only. I can not write it under the load form event because I need value "D" set on the combo only when I click the Bt1. Regular user still should be able to select between A,B,C or D when he loads the Frm1 to input a new record.
    I tried Me.cbo1="D", also tried Me.cbo1.column(1)="D" under the Bt1 click event and both of them failed. What have I done wrong? How can I get it done?
    Thank you all for your attention.


    Cheers,

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Normally cbo1="D" is correct, BUT, is D the actual value? Is there only 1 column?

    if cbo1 has 2 fields and D is what the user sees, but the VALUE is field 2 ,example:"Digital" is being set , then cbo1 must be set to "Digital". The BOUND COLUMN.
    Do you follow?

    If you the combo data is:
    D, "Digital"
    A, "Apple"


    A is seen but col 2 is the bound column,
    then cbo1 = "Apple" is the correct assignment.

  3. #3
    edson is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2014
    Posts
    57
    Quote Originally Posted by ranman256 View Post
    Normally cbo1="D" is correct, BUT, is D the actual value? Is there only 1 column?

    if cbo1 has 2 fields and D is what the user sees, but the VALUE is field 2 ,example:"Digital" is being set , then cbo1 must be set to "Digital". The BOUND COLUMN.
    Do you follow?

    If you the combo data is:
    D, "Digital"
    A, "Apple"


    A is seen but col 2 is the bound column,
    then cbo1 = "Apple" is the correct assignment.
    Dear ranman256, good morning.
    Yes, the Cbo1 has 2 columns: Column "0" is the ID (the user does not see it), and the column "1" is for the values A,B,C or D (the user sees that particular column).
    My trials were: me.cbo1="D" also me.cbo1.column(1)="D" and me.cbo1.column(0)=4 (where 4 stands for the value "D"). They all failed.
    It is curious that if I do me.cbo1=Null the cbo1 will clean up. So I also tried to clean it up first and then set the value as shown above but it did not work either.
    It seems to be a basic knowledge instruction but it has driven me crazy.
    Any other ideas please?
    Thank you.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    What is the field that combobox is bound to? What data type? Why do you have the ID field in the combobox RowSource? Is the ID supposed to be saved to the record? Is ID an autonumber field? If yes then the field combobox is bound to must be a number type. If this is the case then cannot populate the combobox with A, B, C, D. Must populate with the corresponding ID.

    Why are you picking on "D"? What is the ID associated with "D"?
    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.

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    My method works. Put the column 'value' in the text box, then the query can read the text box.
    I do this all the time.
    txtbox = cboBox.column(3)


    NOW REMEMBER....column # starts at zero!
    using properties, col 1 = col 1
    but in code... cboBox.column(0) means column 1.
    you could be off by 1.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    ranman, I think OP wants to populate a combobox with a given value, not populate textbox from combobox.
    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
    edson is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2014
    Posts
    57

    Forcing a value on a combo box by clicking a form button

    Quote Originally Posted by June7 View Post
    ranman, I think OP wants to populate a combobox with a given value, not populate textbox from combobox.
    Hello June 7. You got it right. I want to populate a combobox with a given value. I just used hypothetical field names in the thread assuming you do not read Portuguese.
    So, like I said before, Cbo1 has 2 columns: The first Column (column 0) is autonumbered and Its called LetterId. User does not see it.
    The Cbo1 second column is for the values A,B,C and D and its called Letter. So the aspect of the Combo is:
    Column 0 Column 1
    Invisible Visible
    Letter_ID Letter
    1 A
    2 B
    3 C
    4 D
    Cbo1 is bounded by the column 0.

    This Cbo1 is part of a Form Frm1, which also has a bottom Bt1. By clicking Bt1 my record intentionally duplicates. So I'll have Frm1 open with a new record in which the Cbo1 is enabled.
    Now, what I need is to force Cbo1 to be populated with the Letter "D" (corresponding to Column 0 = 4) as soon as I click on the bt1.
    I also said that I believe I should not get it done thru the Frm1 load event because if I do so, the user will not be able to pick among A, B, C ou D by the time he loads Frm1 in a different instance (like adding a new record for example). I only want the Cbo1.fieldLetter to be populated with "D" when I, and only I, click the Bt1 of the Frm1.

    My trials were: me.cbo1="D" also me.cbo1.column(1)="D" and me.cbo1.column(0)=4 (where 4 stands for the value "D"). They all failed.
    It is curious that if I do me.cbo1=Null the cbo1 will clean up. So I also tried to clean it up first and then set the value as shown above but it did not work either.

    I wonder if it is Crystal clear now.
    It seems to be a basic knowledge instruction but it has driven me crazy.

    Thank you for your help.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Didn't answer my questions from post 4.

    Referencing the column index is meaningless for populating the box. Try just:

    Me.cbo1 = 4
    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.

  9. #9
    edson is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Oct 2014
    Posts
    57
    You are the master. It did work like a charm. Thank you once more.
    I just learned one more.
    Have a blessed day.
    Edson

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

Similar Threads

  1. Copy data from form to form by clicking a button
    By tswack in forum Programming
    Replies: 3
    Last Post: 02-24-2014, 12:01 PM
  2. Replies: 3
    Last Post: 10-30-2013, 05:59 AM
  3. Replies: 3
    Last Post: 07-11-2013, 11:52 AM
  4. Replies: 5
    Last Post: 08-02-2012, 02:05 PM
  5. Enable button in the master form when clicking in the detail
    By DistillingAccess in forum Programming
    Replies: 8
    Last Post: 08-03-2010, 10:54 AM

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