How to create a new UserForm in Access VBA

G

Guest

This is a very basic question...
When I open the Project window in the Visual Basic Editor in Access, I can't
find a way to create a new UserForm - only modules.
I'm looking for something like the possibility n the Visual Basic Editor in
Word (with which I'm more familiar) of selecting Insert and then UserForm.
Would be grateful for any help.
 
I

IanOxon via AccessMonster.com

As you said the VBE in Access doesn't display anything else than modules.
The database objects have to be created using the Access UI. Go to the
database window and select the tab listing form objects you want to create
and click on the New command button. It's pretty straight forward from there.


Regards

Ian
 
G

Guest

Thanks a lot! I have done that with a few of the forms I wanted to create.

I also realized I could create the forms in the VBE in Word, and then import
them into Access. I have done that with a few other forms.

Regards

Matias
-------------------
 
G

Guest

I've just discovered something really bizarre... In the Access Visual Basic
Editor, if you right-click on the toobar, select 'Customize', 'Commands' and
'Insert', you will find a button for... adding UserForms!

So, although the command seems not be available in the menus, by adding the
button to my toolbar, I now can add UserForms in Access VBE.

I'm surprised I had never heard of that before.

Matt
 
T

Tom Lake

Matt Vilhena said:
I've just discovered something really bizarre... In the Access Visual
Basic
Editor, if you right-click on the toobar, select 'Customize', 'Commands'
and
'Insert', you will find a button for... adding UserForms!

So, although the command seems not be available in the menus, by adding
the
button to my toolbar, I now can add UserForms in Access VBE.

Now that I've created a nice user form how do I use it in Access?

Tom Lake
 
G

Guest

Not very sure about what you mean...
Well, you write code related to it and to the objects you have put on it,
like command buttons, etc.
 
T

Tom Lake

Matt Vilhena said:
Not very sure about what you mean...
Well, you write code related to it and to the objects you have put on it,
like command buttons, etc.

How do you display it? It's not like a normal Access form.

Tom Lake
 
G

Guest

You have to write code to display the UserForm. If you gave it the name
frmTest, then the code would be:

Load frmTest
frmTest.Show

You could, for instance, write this code in in a module that you name
AutoExec. This name means it will play every time you open the database, and
so your UserForm would be shown every time the database is opened.

You could also, alternatively, attach this code to an event in a normal
Access form. In Design mode, right-button click the normal Access form,
select Properties, select Event, click on the event you want to attach the
code to. Then click the button with 3 dots that will appear at the right of
that event line, and select 'Code Builder'. Write those two lines of code on
the page that will appear.

To close the UserForm, you could add to it an OK command button, name it
(for instance) cmdOK and write these lines on the code page of your UserForm:

Private Sub cmdOK_Click()
frmTest.Hide
Unload frmTest
End Sub

I like to employ those UserForms because I'm accostumed to their features,
which I used a lot in MS Word and Excel. But the normal Access forms have
their own features, which are also very comprehensive, and you can use them
as pop up forms (in Design mode / Properties / Other, select 'Yes' in front
of 'Pop up').

So if you are familiar with the normal Access forms, it might be that
employing the VB UserForms doesn't add much - I don't know, that's for the
experts here to say.

Matt Vilhena
-----------------------
 

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