Results 1 to 13 of 13
  1. #1
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107

    How do I make a button caption "permanent"?


    I have created a button on a form that opens another form. If the user changes the data in a particular field on the 2nd form, I want to change the caption on the button on the first form to the text in that field. This is the code I use:

    Private Sub BinNumbertxt_AfterUpdate()
    Forms!frmFGmap!button357.Caption = [BinNumbertxt]
    Me.Refresh

    End Sub

    This appears to work. When I close the 2nd form, the caption on the button on the first form reflects what the user entered. But when I close the original form and then reopen it, the original caption is back. Why? How do make the caption change "permanent" until the user changes the field again?

    Thanks.

  2. #2
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    This would not be an ideal method - text for command buttons should not change. Above the command button you can have a locked text box which displays BinNumbertxt - you would still be left, though, with it being 'cleared out' next time form is re-opened. Perhaps you can explain the purpose of doing this and we can advise a better method.

  3. #3
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107
    I have created a form of buttons that is a visual map of our stock floor. Each button represents a bin location on our stock floor. The user can click on a button and a 2nd form opens with the bin information (including bin number) and a list of part numbers that are in that location. (This part works! ) If the user changes the number of the bin location, I want the button to reflect the new name without having to be changed manually.

    Another goal I have is to create a part locater. The user will click on a "Locate" button. Based on a query of item locations, I want to change the backcolor of each of the bin number buttons where this item is located to give a visual to the user where these items can be found. I also haven't worked all of the kinks out of this either. Any suggestions?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    You might try:
    DoCmd.Close acForm, "frmFGmap", acSaveYes

    ...after setting the caption and then open it back up again.

  5. #5
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107
    I tried that (DoCmd.Close acForm, "frmFGmap", acSaveYes) and it didn't work. I also tried the SaveObject command in a macro on the On Close event of the form with the button and that didn't work either.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    The only thing left is the OnLoad event of the frmFGmap Form to set the caption of the button if there is a way.

  7. #7
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107
    The bin numbers do not change very often. I will just resolve to change them manually when this happens.

    Thank y'all for your advice.

  8. #8
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    Is this like "remember lasts viewed" scenario? If so, On close of the form, save the bin number to a table (tblDefaults, perhaps). Then OnLoad of the form, read-in that value and set the command button caption. And/or, if the bin number is always selected from the first form and then the second form is opened to that bin number, than pass the bin number using OpenArgs and set it in the Open event. Different ways to do different things... If still no go, post a shell of your DB with enough to replicate what you are trying to do.

  9. #9
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Saving the caption to a Table, as jwhite suggested, then retrieving it and applying it in the Form's OnOpen or OnLoad event is the only real way to do this, I think. Your original approach would only work if the change was made while the first Form was in Design View.

    Linq ;0)>

  10. #10
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107
    I am already saving the Bin Numbers in a table, so I will apply them in the form's OnLoad event as you suggest. This leads me to another question... I have almost 600 bins so I have almost 600 textboxes to load captions into. Before I write almost 600 lines of code to load each of these, is there a way to put my textbox names (or some other object property) in an array so I can write a loop to load them? I have tried naming my textboxes Bin(1), Bin(2), etc., and referring to them with a loop variable, but with no success. Apparently you can't refer to an object property with a variable name. Please let me know if I am not making sense.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Quote Originally Posted by klnlsu View Post
    I have tried naming my textboxes Bin(1), Bin(2), etc., and referring to them with a loop variable, but with no success. Apparently you can't refer to an object property with a variable name. Please let me know if I am not making sense.
    You just need the right syntax. It would have been better if you had NOT put parens in the name and instead used Bin1, Bin2...etc.
    Me.Controls("Bin" & LoopingVariable) will reference your textboxes.

  12. #12
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107
    That worked great! Like I said, I have almost 600 bins so there are almost 600 textboxes to load with data so the form takes over a minute to load. (There is also some conditional formatting on every textbox that slows it down.) That is rather slow, but once the user has the form open, they will hardly ever close it. All of their processing is done from that form.

    By the way, I started out using command buttons, but changed my bins to textboxes so I could use conditional formatting for my "Locate" function. That also is a little slow but serves its purpose.

    Thank you RuralGuy, jwhite, and MissingLinq for y'all's help!

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    We're all glad you got it working and you're welcome.

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

Similar Threads

  1. Replies: 4
    Last Post: 02-06-2015, 03:58 AM
  2. Replies: 3
    Last Post: 03-28-2013, 12:58 PM
  3. Replies: 2
    Last Post: 05-25-2012, 11:31 AM
  4. Replies: 11
    Last Post: 03-29-2012, 02:32 PM
  5. Replies: 0
    Last Post: 01-11-2012, 12:34 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