Results 1 to 11 of 11
  1. #1
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245

    string on button to update field values

    Hello,

    I get an error for this code: this is the error, i can firgure out how to have the string not be the textbox, but sub in the texbox name. thanks,



    Code:
    myFormstr = Array("F_Value1", "F_Value2", "F_Value3", "F_Value4", "F_Value", "F_Value6", "F_Value7")
    For Each mystr In myFormstr
    me.cboProduct = Me.mystr
    Next mystr

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I don't understand what you are trying to do.......


    I don't think you can reference an array the same way as a collection.

    I would use something like this (air code):
    Code:
    Dim x as Integer
    Dim myFormstr
    
    myFormstr = Array("F_Value1", "F_Value2", "F_Value3", "F_Value4", "F_Value", "F_Value6", "F_Value7")
    
    For x = 0 to UBound(myFormstr)-1
      me.cboProduct = myFormstr(x)
    Next
    In this example, me.cboProduct will always be set to "F_Value7" because the combo box is a) unbound or b) the current record never changes.

  3. #3
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245
    im running into the same issue, where that changes the value of the combo box, Its not updating the value of the text boxes... the names in the array, are names of a set of textboxes im trying to change.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Can I ask what you're trying to do? Are you trying to populate the value of a series of combo boxes with something (i.e. reset them all) or are you trying to have them automatically select a specific value?

    if you're trying to have them populate a specific value you have to use the BOUND COLUMN in your array, which I doubt is the text value.

    Perhaps if you say what exactly you're trying to do with this code there may be a better solution.

  5. #5
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245
    when i click my button, what i want to do is have it put the value in cboproduct, into the respected combo boxes of F_Value1, F_Value2, and so on....

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    You need a two dimensional array then, not a single dimension. You'd need the array to have BOTH the combo box name AND the value you want to change it to if you're determined to do it this way. Additionally the value you want to change the combo box TO would have to be the BOUND COLUMN value (probably not a string if you have a properly normalized database). There is probably a better way to do this if your array is actually a query and it's sorted in the order you want to populate the combo boxes.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You want to put the value (the same value) from the combo box into 7 other combo boxes?
    what are the row sources of the combo boxes?
    How do you know the bound column value in cboProduct will match a bound column value in the other combo boxes???


    BTW, you are missing the 5 in one of the names
    myFormstr = Array("F_Value1", "F_Value2", "F_Value3", "F_Value4", "F_Value", "F_Value6", "F_Value7")

  8. #8
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245
    the row sources, take the number that i want inserted and shows a text value, so a user can understand it instead of its id number. and Yes i want to put it in the 7 Combo Boxes.

  9. #9
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    clear as mud!

    If you are trying to copy the value that's in one field to 7 other fields you can do that without using an array.

    If you are trying to copy 7 different values into 7 different fields you can do that as well with either a 2 dimensional array or without using an array at all

    if you are attempting to copy a value to a combo box you must use the BOUND COLUMN of that list box to copy (for instance if you have a combo box of employees, the EMPLOYEE ID would be your BOUND column) or your combo boxes will be blank at best, and you'll get error messages at worst.

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    As rpeare said, "Clear as mud".

    It is still not clear as to what you want to do.... if we understood what you are trying to do (not how), we would be able make better recommendations

    Here are three methods to fill the controls:

    Your array:
    Code:
    Private Sub Command16_Click()
       Dim x As Integer
       Dim myFormstr
       Dim v As Integer
    
       myFormstr = Array("F_Value1", "F_Value2", "F_Value3", "F_Value4", "F_Value5", "F_Value6", "F_Value7")
    
       v = UBound(myFormstr)
       For x = 0 To UBound(myFormstr)
          Me(myFormstr(x)) = Me.cboProduct
       Next
    End Sub
    Brute force:
    Code:
     Private Sub Command17_Click()
       F_Value1 = Me.cboProduct
       F_Value2 = Me.cboProduct
       F_Value3 = Me.cboProduct
       F_Value4 = Me.cboProduct
       F_Value5 = Me.cboProduct
       F_Value6 = Me.cboProduct
       F_Value7 = Me.cboProduct
    End Sub
    For...next loop:
    Code:
    Private Sub Command18_Click()
       Dim x As Integer
    
       For x = 1 To 7
          Me("F_Value" & x) = Me.cboProduct
       Next
       
    End Sub
    If the first column is the PK and the second column is text that you want in the controls, change Me.cboProduct to Me.cboProduct.Column(1)

  11. #11
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245
    awesome thanks for the help!

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

Similar Threads

  1. Replies: 5
    Last Post: 02-20-2013, 03:21 PM
  2. Replies: 7
    Last Post: 04-18-2012, 11:38 AM
  3. Update Query selecting multiple values in one field
    By Zipster1967 in forum Queries
    Replies: 1
    Last Post: 08-15-2011, 12:22 PM
  4. Replies: 0
    Last Post: 07-05-2011, 10:24 PM
  5. Changing Field Values with Command Button
    By avarusbrightfyre in forum Access
    Replies: 1
    Last Post: 08-22-2010, 12:48 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