Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control settings not saving 1

Status
Not open for further replies.

Thurls

MIS
Joined
Jun 15, 2003
Messages
9
Location
AU
Hello all,

I have a button on a form that controls if some fields are visible or not.

By clicking the button the VB code sets the required fields visible property to False and they fields disapear.

However when I exit the form and load it again the fields are back and their visible property is back to true.

Any ideas on how I can save the settings and ensure they remain not visible?

Thanks
 
It would probably be better if you set the controls visible by a control rather than a button.
if a certain control = -1/true the
XXX.visible = false

and run the code on current

Hope this helps
Hymn
 
How are ya Thurls . . . . .

This is normal! A form always opens with the [purple]last saved settings (property defaults) made in design view[/purple]. If you want to permanently change a property it has to be done in design view. You can do this manually or thorugh code.

Calvin.gif
See Ya! . . . . . .
 
Thanks AceMan!

Thought I was going crazy. Can you give me an example of a simple code that I could use behind a button to make the changes in design view, save them and return the form to normal view?

Thurls
 
OK Thurls . . . . .

Add the following code to a module in your module window:
Code:
[blue]Public Sub SaveProps(frmName As String)
   [green]'Note: If frmName is a subForm you have to use
   'the main form Name instead![/green]
   
   Dim frm As Form
   
   Application.Echo False [green]'Stop updating screen[/green]
      DoCmd.OpenForm frmName, acDesign
      Set frm = Forms(frmName)
      
      [green]'Your property changes here[/green]
      frm!CheckID.Visible = False
                 '
                 '
      
      DoCmd.Close acForm, frmName, acSaveYes
      DoCmd.OpenForm frmName
   Application.Echo True [green]'Allow screen updates[/green]
 
End Sub

Public Function RestoreEchoHG()
   DoCmd.Hourglass False
   Application.Echo True
   
   Msg = "Application Echo is on!"
   Style = vbInformation + vbExclamation + vbOKOnly
   Title = "Forced Echo On!"
   MsgBox Msg, Style, Title

End Function[/blue]
In the click event of your button add the following call:
Code:
[blue]   [green]'Note: If frmName is a subForm you have to use
   'the main form Name instead![/green]
   Call SaveProps(frmName As String)[/blue]

Now . . . . there's an issue with [blue]Application.Echo False[/blue]. If for any reason the code locks-up or there's an error while screen updating is off, you won't be able to do anything. It will appear as if you can do nothing. So ya need to setup a hotkey for safety. This puts everything back to normal. You should never have to use it, but . . . . you never know. Besides, without the Echo, the switching back & forth between design and form view is ugly! To see it for yourself just disable the Application.Echo False line and you'll see what I mean.

1) In the macros window open a new macro.
2) In The [blue]Macro Name[/blue] column enter [purple]^E[/purple] (this sets the hotkey to Ctrl + E).
3) In the [blue]Action[/blue] column select [purple]RunCode[/purple].
4) In the [blue]Function Name[/blue] at the bottom enter [purple]RestoreEchoHG()[/purple].
5) In the next action line select [purple]StopMacro[/purple].
6) Close the macro window and be sure to save it as [purple]AutoKeys[/purple].
7) Test it by hitting Ctrl + E.

Thats it! . . . . Give it a whirl and let me know . . . .

Calvin.gif
See Ya! . . . . . .
 
ooops . . . . .

Call SaveProps(frmName As String) should be
Call SaveProps(frmName)

Calvin.gif
See Ya! . . . . . .
 
Fantastic, I'll give it a go!

Thurls
 
Yep worked like a dream, thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top