Programmatically creating AND saving form

R

Ruben Lysemose

Hi guys
Does anybody know how to 1) save a programmatically
created form -
dim frm as form
set frm = CreateForm()

- with 2) a specific name ?

1. When I use the DoCmd.Save or DoCmd.Close I encounter an
error 29068 (something like "Access cannot complete this
action. Stop the code and try again" - freely translated
from Danish)
2. When I try to set the name prop. of the form I'm told
it is read-only.

I have users designing survey-forms by entering the
questions in a db. From those questions I genererate a
suitable form for use in the a survey. The problem is not
generating the form but saving with a given name, so my
app can find it again.
Thanks!
Ruben Lysemose
 
D

Dan Artuso

Hi,
This will do it:

Public Sub NewForm(frmName As String)
Dim frmNew As Form
Dim frmOldName As String

Set frmNew = CreateForm()
'get the name Access gave it
frmOldName = frmNew.Name
'save it and cloe it
DoCmd.Save acForm, frmOldName
DoCmd.Close acForm, frmOldName

'name it what you want
DoCmd.Rename frmName, acForm, frmOldName
Set frmNew = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top