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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you save a programmatically created UserForm 1

Status
Not open for further replies.

patriciaxxx

Programmer
Jan 30, 2012
277
GB
I have the following sub in an Access module which creates a simple UserForm and then displays it. However when you close the form and exit the datadbase it then promps you to save the form. This is no good.

I need the code to save the form.
How do you do this within the code?

Code:
[COLOR=#204A87]Public Sub AddControls()
Dim MyNewForm As VBComponent
Dim myCheckBox As MSForms.Control
Set MyNewForm = Application.VBE.ActiveVBProject.VBComponents.Add(vbext_ct_MSForm)
Set myCheckBox = MyNewForm.Designer.Controls.Add("Forms.CheckBox.1")
With myCheckBox
    .Name = "Check1"
    .Caption = "Check here"
    .Left = 10
    .Top = 10
    .Height = 20
    .Width = 60
End With

[COLOR=#4E9A06]'...something here to save the UserForm[/color]
UserForms.Add(MyNewForm.Name).Show
[COLOR=#4E9A06]'...or here[/color]

End Sub
[/color]
 
Curiously I have just noticed that while it does indeed solve the save issue the code infact is still decompiled.

I also tried this but again the UserForm is saved but the code is not compiled.

RunCommand acCmdCompileAndSaveAllModules
RunCommand acCmdCompileAllModules

Any idea what I’m doing wrong?
 
(if you mean that application.iscompiled is false, then that just means you have an error *somewhere* in your code, not necessarily related to the new form at all)
 
If I run the command

RunCommand acCmdCompileAndSaveAllModules

out of the sub then the code compiles but if I run the same command in the sub the code is not compiled but the form is saved.

Or if I I click the debug menu in Visual Basic Editor and click compile the code compiles
 
I don't think you can compile a running procedure ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
As PHV says.

But your requirement was to save the form, which it does. The compile bit was just a kind of bonus (mainly because there isn't a simple acCmdSaveAllModules ... well ... there IS ... but it is obscure ... SysCmd(504, 16484))
 
I understand, and thank you guys for taking the time to explain it to me.

…like strongm says it was the Save I needed the compile would have been a bonus but I can always run

RunCommand acCmdCompileAllModules

somewhere else to compile the code.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top