Starting a form from another form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

Sorry to bother you with simple questions, but it's a long time since I did
Access VBA...

I have a main form which is kicked off by the Autoexec macro. But before
this form is opening, I'd like to:

1) open another form that will ask the user to choose a department from a
combo box. When the user has chosen, he will close that form
2) get the value of the chosen department from that form

I have 2 problems:
a) I can't seem to find the syntax that will load the other form from the
main form. I've used application.Forms!Form_OtherForm.Load, but that
generates an error
b) I don't know how to get the variable that was set in the other form
"passed" to the main form

Can you help me on both issues ? Thanks.

Bernard
 
Hi

Sorry to bother you with simple questions, but it's a long time since I did
Access VBA...

I have a main form which is kicked off by the Autoexec macro. But before
this form is opening, I'd like to:

1) open another form that will ask the user to choose a department from a
combo box. When the user has chosen, he will close that form
2) get the value of the chosen department from that form

I have 2 problems:
a) I can't seem to find the syntax that will load the other form from the
main form. I've used application.Forms!Form_OtherForm.Load, but that
generates an error
b) I don't know how to get the variable that was set in the other form
"passed" to the main form

Can you help me on both issues ? Thanks.

Bernard

1) Don't use the AutoExec at all.
Open this other form (that will ask for the department) from:
Tools + StartUp. Enter the name of this form in the Display Form/Page
drop-down box.

Code a command button click event on this form:
DoCmd.OpenForm "MainForm", , , , , , Me![ComboName]
DoCmd.Close acForm, Me.Name


Code the Declarations section of the Main Form:

Option Compare Database
Option Explicit
Dim strDepartment as String
=============

Code the Load event of the Main Form:

If Not IsNull(Me.OpenArgs) then
strDepartment = Me.OpenArgs
End If

When the database is first opened, the Department selection form will
display. Select the Department and click the command button.
This form will then close and the main form will open.
strDepartment contains the value selected in the combo box.
You can use it anywhere in the form.
 
1. Use the AutoExec to open the form that the user can select department from
2. Create a button on the above form that used to open the next form and
close the current form.
3. The code you can use on the OClick event of the first form to open the
next form

Dim MyCriteria As String
If IsNull (Me.[DepartComboName]) Then
MsgBox "Must Select a department"
Else
MyCriteria = "[DeptFieldNameInTable] = " & Me.[DepartComboName]
Docmd.OpenForm "SecondFormName" , , , MyCriteria
DoCmd.Close acForm, "FirstFormName"
End If
=====================
If the department field is text then use that in the filter:
MyCriteria = "[DeptFieldNameInTable] = '" & Me.[DepartComboName] & "'"
 
Thanks guys, this did it ! Works like a breeze

And I'd spent loads of time finding that out !

The only thing is: the number of commas indicated by Cohen in the DoCmd to
open the main form was wrong, but Fred's was right. AND: Fred indicated how
to retrieve the value, which was also pretty essential for me !

Have a nice we.
Bernard

fredg said:
Hi

Sorry to bother you with simple questions, but it's a long time since I did
Access VBA...

I have a main form which is kicked off by the Autoexec macro. But before
this form is opening, I'd like to:

1) open another form that will ask the user to choose a department from a
combo box. When the user has chosen, he will close that form
2) get the value of the chosen department from that form

I have 2 problems:
a) I can't seem to find the syntax that will load the other form from the
main form. I've used application.Forms!Form_OtherForm.Load, but that
generates an error
b) I don't know how to get the variable that was set in the other form
"passed" to the main form

Can you help me on both issues ? Thanks.

Bernard

1) Don't use the AutoExec at all.
Open this other form (that will ask for the department) from:
Tools + StartUp. Enter the name of this form in the Display Form/Page
drop-down box.

Code a command button click event on this form:
DoCmd.OpenForm "MainForm", , , , , , Me![ComboName]
DoCmd.Close acForm, Me.Name


Code the Declarations section of the Main Form:

Option Compare Database
Option Explicit
Dim strDepartment as String
=============

Code the Load event of the Main Form:

If Not IsNull(Me.OpenArgs) then
strDepartment = Me.OpenArgs
End If

When the database is first opened, the Department selection form will
display. Select the Department and click the command button.
This form will then close and the main form will open.
strDepartment contains the value selected in the combo box.
You can use it anywhere in the form.
 
Back
Top