Page 1 of 2 12 LastLast
Results 1 to 40 of 44

Thread: How to save selected stuff on Userforms...[RESOLVED]

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Resolved How to save selected stuff on Userforms...[RESOLVED]

    Hi,

    I just wanted to save the details a user select from userforms (ie. from option boxes, and checklists) so that when they reload that userform the details they selected earlier was still on it. Not sure how to do it though???

    Thanks.
    Last edited by chaos7; Jun 15th, 2005 at 10:11 PM. Reason: no longer required

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: How to save selected stuff on Userforms...

    Save it in a table if you want it saved between sessions, or in global variables if the same session. It could be saved to the registry, but don't know if VBA can do that.
    Tengo mas preguntas que contestas

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    Is there any examples of this on the forum?? I'm not sure how to thats all...i couldn't find it in the book im looking at...if there is a simple example that someone can show me it would be really good...

    Thanks.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to save selected stuff on Userforms...

    GetSetting and SaveSetting functions are part of the core of VBA.
    They read/write to the "HKEY_CURRENT_USER\Software\VB and VBA Program Settings" section.

    VB Code:
    1. 'Write to the registry:
    2. SaveSetting "MyName", "MySection", "MyKey", "MyValue"
    3.  
    4. 'Read from the registry:
    5. Dim strString As String
    6. 'The default parameter is for when there is no value for tthe specified key
    7. strString = GetSetting("MyName", "MySection", "MyKey", "MyDefaultValue")
    8. MsgBox strString
    Last edited by RobDog888; Jun 8th, 2005 at 10:28 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    thanks rob, i'll test this out once i get home, and hassle u if i have problems

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to save selected stuff on Userforms...

    Your welcome and its not a hassle att all. Just post back if you need anything else.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    hi rob,

    i'm not sure how to apply the SaveSetting and GetSetting to my program. basically i am creating a home auto program, so for example a room in my house will give the user options for light settings (i.e dim, medium, or high), temp settings,light sensors etc. So if the user clicks on the option button of dim (light setting), i want it to return dim when i open it up again?? Don't know if its helpful but i've copied and pasted some of the form code below:
    VB Code:
    1. Private Sub HighButton_Click()
    2.     ShowSettings
    3. End Sub
    4.  
    5. Private Sub DimButton_Click()
    6.     ShowSettings
    7. End Sub
    8.  
    9. Private Sub MediumButton_Click()
    10.     ShowSettings
    11. End Sub
    12.  
    13. Public Sub ShowSettings()
    14.  
    15.     'Declare variables
    16.         Dim Info
    17.         Dim LFCR
    18.        
    19.         LFCR = Chr(13) + Chr(10)
    20.        
    21.     'Dim Level
    22.         If DimButton.Value = True Then
    23.             Info = "Dim Light Settings: ON"
    24.         End If
    25.  
    26.     'Medium Level
    27.         If MediumButton.Value = True Then
    28.             Info = Info + LFCR + "Medium Light Settings: ON"
    29.          End If
    30.  
    31.       'High Level
    32.         If HighButton.Value = True Then
    33.             Info = Info + LFCR + "High Light Settings: ON"
    34.             End If
    35.          
    36.                    
    37.              LabelChoice.Caption = Info
    38.            
    39. End Sub

  8. #8
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: How to save selected stuff on Userforms...

    One other issue is if the user is always on the same machine. If they may be on more than one machine, saving to the registry may not be appropriate because those settings are local to a particular machine, and won't be on other machines.
    If the user has a roaming profile, maybe you can save settings there, but that's beyond my knowledge. Or create some kind of user table where you save settings in that case.
    Tengo mas preguntas que contestas

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to save selected stuff on Userforms...

    I would do something like this...
    VB Code:
    1. Option Explicit
    2.  
    3. Private msSelection As String
    4.  
    5. Private Sub HighButton_Click()
    6.     msSelection = "High"
    7.     UpdateCaption
    8. End Sub
    9.  
    10. Private Sub DimButton_Click()
    11.     msSelection = "Dim"
    12.     UpdateCaption
    13. End Sub
    14.  
    15. Private Sub MediumButton_Click()
    16.     msSelection = "Medium"
    17.     UpdateCaption
    18. End Sub
    19.  
    20. Private Sub UpdateCaption()
    21.     Select Case msSelection
    22.         Case "Dim"
    23.             LabelChoice.Caption = "Dim Light Settings: ON"
    24.             LabelChoice.Caption = "Medium Light Settings: OFF"
    25.             LabelChoice.Caption = "High Light Settings: OFF"
    26.         Case "Medium"
    27.             LabelChoice.Caption = "Dim Light Settings: OFF"
    28.             LabelChoice.Caption = "Medium Light Settings: ON"
    29.             LabelChoice.Caption = "High Light Settings: OFF"
    30.         Case "High"
    31.             LabelChoice.Caption = "Dim Light Settings: OFF"
    32.             LabelChoice.Caption = "Medium Light Settings: OFF"
    33.             LabelChoice.Caption = "High Light Settings: ON"
    34.     End Select
    35. End Sub
    36.  
    37. Private Sub Form_Load()
    38.     'Read from the registry:
    39.     msSelection = GetSetting("MyName", "MySection", "MyKey", "Medium")
    40.     UpdateCaption
    41. End Sub
    42.  
    43. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    44.     'Write to the registry:
    45.     SaveSetting "MyName", "MySection", "MyKey", msSelection
    46. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    hi rob...i gave it a shot but it doesnt work the program compiles but doesnt save it?? i'll try to play around with it and see if something comes up..

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to save selected stuff on Userforms...

    Doh! forgot to write it in VBA.

    Use these two events instead.

    VB Code:
    1. Private Sub UserForm_Initialize()
    2. 'Form_load
    3. End Sub
    4.  
    5. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    6. 'Form_queryunload
    7. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    no....it's not saving...
    i tried to even incorporate it back into my earlier code, but won't work (it compiles and all, just doesnt save what i selected, so that when i open the form again its a clear form without the previous selection)..

  13. #13

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    Just another thing...how do i get a vertical scrollbar on a userform to scroll the form up and down?? i placed a scrollbar on my form and when i run it it shows up on my form but wont let me use the scroll to move the form up and down?? i don't understand why they don't write this kind of stuff in the latest text im reading...."Idiot's guide to Visual Basic"

  14. #14
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to save selected stuff on Userforms...

    post your code again, as i can't see anything obvious wrong

    pete

  15. #15

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    hi..there is nothing wrong with my code. it works fine and let user select options and checklists on the userform BUT does not save it so if they run the userform again...the options they previously selected are not on the userform...thats what im trying to find out..

  16. #16
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to save selected stuff on Userforms...

    i can't make any suggestions why it is not saving without seeing some of your code, robdogs suggested code should work fine

    pete

  17. #17

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    hi..my code is pasted above...but here it is again:

    VB Code:
    1. Private Sub HighButton_Click()
    2.     ShowSettings
    3. End Sub
    4.  
    5. Private Sub DimButton_Click()
    6.     ShowSettings
    7. End Sub
    8.  
    9. Private Sub MediumButton_Click()
    10.     ShowSettings
    11. End Sub
    12.  
    13. Public Sub ShowSettings()
    14.  
    15.     'Declare variables
    16.         Dim Info
    17.         Dim LFCR
    18.        
    19.         LFCR = Chr(13) + Chr(10)
    20.        
    21.     'Dim Level
    22.         If DimButton.Value = True Then
    23.             Info = "Dim Light Settings: ON"
    24.         End If
    25.  
    26.     'Medium Level
    27.         If MediumButton.Value = True Then
    28.             Info = Info + LFCR + "Medium Light Settings: ON"
    29.          End If
    30.  
    31.       'High Level
    32.         If HighButton.Value = True Then
    33.             Info = Info + LFCR + "High Light Settings: ON"
    34.             End If
    35.          
    36.                    
    37.              LabelChoice.Caption = Info
    38.            
    39. End Sub

  18. #18
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to save selected stuff on Userforms...

    but where is the part to save your settings??

    pete

  19. #19
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to save selected stuff on Userforms...

    Ok, two things going on here.

    1. You say your compiling the UserForm but userforms in VBA can not be compiled unless you have Office XP Developer ed. So are you using VB6?

    2. You havent made any of the changes to the code that will make it save any settings.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  20. #20

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    hi...im using vb6...and i tried to use the code that you supplied, but that doesnt save the settings either....its compiling and letting me run it but when i re-open it wont save the settings...this is drivng me crazy.....maybe i'll skip this part for the time being - i cant find anything in the texts either which is weird.
    can you give me some help on scrollbars?? how do i get a vertical scrollbar on a userform to scroll the form up and down?? i placed a vertical scrollbar on my form and when i run it, it shows up on my form but wont let me use the scroll to move the form up and down?? how do i get it to work so that i am able to view the form using the scrollbar??
    i've switched on to scrollbar at the moment...its the last thing i have left to complete - just the scrollbar and saving the userform....maybe i'll have better luck with the scrollbar....helppppppp

  21. #21
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to save selected stuff on Userforms...

    Here is a VB6 example for you to do the registry saving.
    Attached Files Attached Files
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  22. #22

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    hi rob,
    i tried the zip file...your code does work...but it does exactly what my code did that i pasted above. The thing is its still not saving. Maybe i've been saying this wrong....but basically i want the user to be able to select all the changes they made (i.e light settings to Dim) so that when they close the form and re-open it again...the form should have Dim light settings selected instead of no selection?? thats the only prob im having...maybe i should have used temp instead of light settings as thats easier to understand....i've pasted the code below...what i have is a label which is blank and a user text screen...when the user enters number into text screen it automatically gets entered into a label...but when i close the form and open it again, the label is empty - which should really have the number the user previously typed in earlier in the text box:
    VB Code:
    1. Private Sub TempVBox_Change()
    2.     NewTemp    
    3. End Sub
    4.  
    5. Public Sub NewTemp()
    6.         TempLabel.Caption = TempVBox.Value
    7. End Sub

    im searchin on net for stuff currently maybe i'll get something by the end of today but sorry for confusing you and everyone else that has read the post and thank you very very very much for taking so much time out to help me

  23. #23
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to save selected stuff on Userforms...

    Maybe we have a communication issue here, but the example will save the current selection upon close to the registry. Then upon
    open of the program it loads the saved setting into the app and populates the label with that selection.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  24. #24

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    but i downloaded the zip file...and placed it onto new userform and tested it out...when i select the command button - the label tells me which button i selected (dim, med, or high) but then when i close the form and reopen it label is empty and doesnt show previous selection (whichever button i had pressed?)...
    hmmm....what am i missing here...??

  25. #25
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to save selected stuff on Userforms...

    Are you pasting the code into VB6 IDE project or behind an Office app's VBA editor?

    Plus, try just running my example project. It should be showing the previously selected setting in the label.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  26. #26
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to save selected stuff on Userforms...

    i tested rob's example, it worked perfectly as i expected it would

    pete

  27. #27

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    yeah okay - then maybe im going absolutely crazy!!

  28. #28
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to save selected stuff on Userforms...

    Did you unzip the two files (.vbp and .frm) and just run that?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  29. #29

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    i opened up the .frm file and copied and pasted it in MSWORD then compiled macro..i don't know how else to run it apart fm putting it in word.

  30. #30
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to save selected stuff on Userforms...

    So then its NOT VB6, its Word VBA. That makes a world of difference.
    Here is a demo userform that opens when you open the word document. Make sure your macros are enabled.
    Attached Files Attached Files
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  31. #31

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    have to go to work now - be back in a few hours....will test it out when i get back in the afternoon...sorry for not specifically saying word VBA i assumed cos it was a VBA forum...and word was the only application used here...or not!!

  32. #32
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to save selected stuff on Userforms...

    Actually you assumed kind of correct. This is the VBA forum, but sometimes threads get posted here when it concerns automating an office
    app from VB6 since they are so closely related.

    I guess you threw me off with the "compiles" since office vba apps can not compile only vb6 can, basically.

    I'll be back online tomorrow. Time for bed. I will check things out tomorrow to see how it went.

    Have "fun" at work.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  33. #33

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    IT WORKS!!! Rob you are B-R-I-L-L-I-A-N-T Now of course i need to ask you a few more questions about this..
    I have put the code you did into my code..and now my userform saves..just want to ask how do i use GetSetting and SaveSetting to put 2 more values?? For example here is my code below that i have used thus far:
    VB Code:
    1. Option Explicit
    2. Private msSelection As String
    3.  
    4. Private Sub CloseButton_Click()
    5.     Unload BathroomForm
    6. End Sub
    7.  
    8. Private Sub HighButton_Click()
    9.         msSelection = "High"
    10.     UpdateCaption
    11.  
    12. End Sub
    13.  
    14. Private Sub DimButton_Click()
    15.         msSelection = "Dim"
    16.     UpdateCaption
    17.  
    18. End Sub
    19.  
    20. Private Sub MediumButton_Click()
    21.         msSelection = "Medium"
    22.     UpdateCaption
    23. End Sub
    24.  
    25. Private Sub SensorLight_Click()
    26.              UpdateCaption
    27. End Sub
    28.  
    29. Private Sub TempVBox_Change()
    30.     NewTemp
    31. End Sub
    32.  
    33.  
    34. Private Sub UpdateCaption()
    35.  
    36.         Dim Info
    37.         Dim LFCR
    38.        
    39.         LFCR = Chr(13) + Chr(10)
    40.  
    41.  
    42. Select Case msSelection
    43.         Case "Dim"
    44.          
    45.             Info = "Dim Light Settings: ON"
    46.             Info = Info + LFCR + "Med Light Settings: OFF"
    47.             Info = Info + LFCR + "HIGH Light Settings: OFF"
    48.            
    49.         Case "Medium"
    50.            
    51.                Info = Info + LFCR + "Dim Light Settings: OFF"
    52.                  Info = Info + LFCR + "Med Light Settings: ON"
    53.                    Info = Info + LFCR + "High Light Settings: OFF"
    54.         Case "High"
    55.            
    56.              Info = Info + LFCR + "Dim Light Settings: OFF"
    57.                Info = Info + LFCR + "Med Light Settings: OFF"
    58.                Info = Info + LFCR + "High Light Settings: ON"
    59.          End Select
    60.      
    61.         'Light Sensoring - if tick in box then sensor "on" or else "off"
    62.         If SensorLight.Value = 0 Then
    63.             Info = Info + LFCR + "Light Sensors: OFF"
    64.             Else
    65.             Info = Info + LFCR + "Light Sensors: ON"
    66.             End If
    67.    
    68.             LabelChoice.Caption = Info
    69.  
    70. End Sub
    71.  
    72. 'Temperature procedure which lets users enter a new temperature value that overwrites
    73. 'the current temperature value in the label.
    74. Public Sub NewTemp()
    75.               TempVLabel.Caption = TempVBox.Value
    76. End Sub
    77.  
    78. Private Sub UserForm_Initialize()
    79.     'Read from the registry:
    80.     msSelection = GetSetting("MyName", "MySection", "MyKey", "Medium")
    81.     UpdateCaption
    82. End Sub
    83.  
    84. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    85.     'Write to the registry:
    86.     SaveSetting "MyName", "MySection", "MyKey", msSelection
    87. End Sub

    how do i add the new temp input value and light sensor value to save also?? currently it is not saving either because i havent saved it to registery...i tried to add the light sensor case onto the UpdateCaption function and it worked but did not add it with the current light settings options..more like overwrote it (if that makes sense)....if you could let me know that would be good....but im just soooo happy most of it saves now.....thank youuuuuuuuuuuu

  34. #34

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    actually maybe its better if i put my code on what i put to "save" the new temp settings instead of just saying i couldnt get it to work.....(will work on the light sensor later)..this is what i put in but it doesn't save..so had to comment out..
    VB Code:
    1. Private tempSelection As String
    2.  
    3. Private Sub TempVBox_Change()
    4.      tempSelection = "Temp"
    5.         NewTemp
    6. End Sub
    7.  
    8. 'Temperature procedure which lets users enter a new temperature value that overwrites
    9. 'the current temperature value in the label.
    10. Public Sub NewTemp()
    11.         Select Case tempSelection
    12.         Case "Temp"
    13.         TempVLabel.Caption = TempVBox.Value
    14.         End Select
    15. End Sub
    16.  
    17. Private Sub UserForm_Initialize()
    18.     'Read from the registry:
    19.     msSelection = GetSetting("MyName", "MySection", "MyKey", "Medium")
    20.    ' tempSelection = GetSetting("MyName", "MySection", "MyKey", "Temp")
    21.     UpdateCaption
    22.     'NewTemp
    23. End Sub
    24.  
    25. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    26.     'Write to the registry:
    27.     SaveSetting "MyName", "MySection", "MyKey", msSelection
    28.    ' SaveSetting "MyName", "MySection", "MyKey", tempSelection
    29. End Sub

  35. #35
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to save selected stuff on Userforms...

    each setting you want save has to have its own keyname, so you give each savesetting a meaningful key name, maybe like this

    SaveSetting "MyName", "Bedroom", "Light Setting", LblLight.Caption
    SaveSetting "MyName", "Bedroom", "Temp Setting", LabelTemp.Caption

    this assumes you would have label for each of your settings
    "My Name" could also have relevance as the unit, location or something

    you can save the value from a variable msSelection, or directly from the label

    on form load, you will need to use getsetting to get all the values from the registry using the same section and key names as they are saved to and put the values in to the labels

    pete

  36. #36

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    thanks westconn for the theory behind SaveSetting and GetSetting - makes much more sense to me now you know i've gone through 5 VB textbooks in the last couple of days and none of them had mentioned it.....anyway am off to bed now....will try my luck on this whole light sensor/temp thing tomorrow morning

  37. #37
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to save selected stuff on Userforms...

    go here for more information on getsetting and anything else you want to know about vb functions, most of which work in vba

    pete

  38. #38

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    alright the temp is still not saving...tried some other ways but still not working...

  39. #39
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to save selected stuff on Userforms...

    Are you compfortable browsing the registry?

    Also, you do have macros enabled in Word?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  40. #40

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    49

    Re: How to save selected stuff on Userforms...

    what do you mean "comfortable browsing registery"?? yep macros are enabled, the light settings is being saved thanks to you - but am trying to get the temp saved, am thinking maybe the UserForm_Initialize() only takes into account 1 getSetting?? umm...i've just copied and pasted what i have below. also just out of curiousity - is this ur full-time job rob??
    VB Code:
    1. Private tempSelection As String
    2.  
    3. Private Sub TempVBox_Change()
    4.      tempSelection = "Temp"
    5.         NewTemp
    6. End Sub
    7.  
    8. 'Temperature procedure which lets users enter a new temperature value that overwrites
    9. 'the current temperature value in the label.
    10. Public Sub NewTemp()
    11.         Select Case tempSelection
    12.         Case "Temp"
    13.         TempVLabel.Caption = TempVBox.Value
    14.         End Select
    15. End Sub
    16.  
    17. Private Sub UserForm_Initialize()
    18.     'Read from the registry:
    19.     msSelection = GetSetting("MyName", "MySection", "MyKey", "Medium")
    20.    ' tempSelection = GetSetting("MyName", "TempSection", "TempKey", "Temp")
    21.     UpdateCaption
    22.     'NewTemp
    23. End Sub
    24.  
    25. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    26.     'Write to the registry:
    27.     SaveSetting "MyName", "MySection", "MyKey", msSelection
    28.    ' SaveSetting "TempName", "TempSection", "TempKey", tempSelection
    29. End Sub

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width