PDA

View Full Version : HELP about vba createform



zhangsir1984
11-15-2008, 10:10 PM
:help
Hi, I'm a new one,I have some difficultiesin my VBA project,so come here for helps

In my project, I create a temporary form with CreateForm command, after create, I find I can't name this form, it auto named form1, and I can't change this name,and also I can't change form' size, though I used

frm = CreateForm
with frm
.height = 6000
.width = 8000
end with
docmd.openform frm.name

or
with frm
.insideHeight = 6000
.insideWidth = 8000
end with

I just want when the form is run,its size is display with 6000 and 8000, But it also doesn't work,
The third question is, form created by CreateForm command doesn't display when I run my project, when I run my VBA project, Access window is minimum, and only my project form is on the display, how could I display it
Three question, may someone can help me?:help

Carl A
11-17-2008, 03:25 PM
createForm uses a template file to create the new form
if no template file is designated then it will use the
Access built-in template so if you have a Form named Form1 then
Access will create the next Form as Form2 and so on.


Sub NewForm()
Dim frm As Form
Dim frmNewName As String
Dim frmOldName As String

frmNewName = "Customers" 'Name for new form

Set frm = createForm()

With frm
.PopUp = True 'Access 2007
.Caption = "Customer"
.Width = 8000 'adjust to suit
.Detail.Height = 6000 'adjust to suit
End With

frmOldName = frm.Name

'save for Rename
DoCmd.Close acForm, frm.Name, acSaveYes
'Rename
DoCmd.Rename frmNewName, acForm, frmOldName
'Display form
DoCmd.OpenForm frmNewName
Set frm = Nothing
End Sub

Another way would be to make a template the size required.
Create a new Form from the template and then rename it.


Sub NewFormFromTemplate()
Dim frm As Form
Dim frmNewName As String
Dim frmOldName As String

frmNewName = "Customers" '< Your form name here

Set frm = createForm(, "Template")

With frm
.PopUp = True 'Needed for Access 2007 (2003? I don't have)
.Caption = "Customers"
End With

frmOldName = frm.Name

'save for Rename
DoCmd.Close acForm, frm.Name, acSaveYes
'Rename
DoCmd.Rename frmNewName, acForm, frmOldName

DoCmd.OpenForm frmNewName
Set frm = Nothing
End Sub