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
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.
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...
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.
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:
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.
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)..
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"
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..
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
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:
Private Sub TempVBox_Change()
NewTemp
End Sub
Public Sub NewTemp()
TempLabel.Caption = TempVBox.Value
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
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.
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...??
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
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!!
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.
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:
Option Explicit
Private msSelection As String
Private Sub CloseButton_Click()
Unload BathroomForm
End Sub
Private Sub HighButton_Click()
msSelection = "High"
UpdateCaption
End Sub
Private Sub DimButton_Click()
msSelection = "Dim"
UpdateCaption
End Sub
Private Sub MediumButton_Click()
msSelection = "Medium"
UpdateCaption
End Sub
Private Sub SensorLight_Click()
UpdateCaption
End Sub
Private Sub TempVBox_Change()
NewTemp
End Sub
Private Sub UpdateCaption()
Dim Info
Dim LFCR
LFCR = Chr(13) + Chr(10)
Select Case msSelection
Case "Dim"
Info = "Dim Light Settings: ON"
Info = Info + LFCR + "Med Light Settings: OFF"
Info = Info + LFCR + "HIGH Light Settings: OFF"
Case "Medium"
Info = Info + LFCR + "Dim Light Settings: OFF"
Info = Info + LFCR + "Med Light Settings: ON"
Info = Info + LFCR + "High Light Settings: OFF"
Case "High"
Info = Info + LFCR + "Dim Light Settings: OFF"
Info = Info + LFCR + "Med Light Settings: OFF"
Info = Info + LFCR + "High Light Settings: ON"
End Select
'Light Sensoring - if tick in box then sensor "on" or else "off"
If SensorLight.Value = 0 Then
Info = Info + LFCR + "Light Sensors: OFF"
Else
Info = Info + LFCR + "Light Sensors: ON"
End If
LabelChoice.Caption = Info
End Sub
'Temperature procedure which lets users enter a new temperature value that overwrites
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
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:
Private tempSelection As String
Private Sub TempVBox_Change()
tempSelection = "Temp"
NewTemp
End Sub
'Temperature procedure which lets users enter a new temperature value that overwrites
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
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
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:
Private tempSelection As String
Private Sub TempVBox_Change()
tempSelection = "Temp"
NewTemp
End Sub
'Temperature procedure which lets users enter a new temperature value that overwrites