Need help with forms and VBA code

  • Thread starter Thread starter Brian
  • Start date Start date
B

Brian

Hello.

I have an application that imports a file, then compares
the file with an older file, adding only non-duplicate
records. I have two ways to compare the files and a form
(frmCompareMethod) that pops up to let you choose what
way you would like.

What is happening is that frmCompareMethod pops up just
fine, but the function that calls it keeps running and
compares the two files in the default manner, not
allowing time for the user to make a choice. How can I
make the calling function pause until the user presses a
button on frmCompareMethod?

Thanks for any help!

Brian
 
Open the form modally.

docmd.OpenForm "frmHi",,,,,acdialog

This causes code execution to halt until 1) the form is closed, or 2) the
form is made not visible.

David Atkins, MCP
 
Brian said:
Hello.

I have an application that imports a file, then compares
the file with an older file, adding only non-duplicate
records. I have two ways to compare the files and a form
(frmCompareMethod) that pops up to let you choose what
way you would like.

What is happening is that frmCompareMethod pops up just
fine, but the function that calls it keeps running and
compares the two files in the default manner, not
allowing time for the user to make a choice. How can I
make the calling function pause until the user presses a
button on frmCompareMethod?

Thanks for any help!

Brian

It sounds as though you need to open frmCompareMethod in dialog mode.
When you open it, use something like

DoCmd.OpenForm "frmCompareMethod", WindowMode:=acDialog

That will cause the calling routine to wait until the form is closed
or -- and this is the key -- hidden.

Then, when the user makes a choice frmCompareMethod, hide the form by
setting its Visible property to False:

Me.Visible = False

At that point, your calling code will resume, and can pick up the chosen
method, close frmCompareMethod, and proceed to compare the files.

The calling code might look roughly like this:

'----- start of example code (air code) -----
Dim intMethod As Integer

DoCmd.OpenForm "frmCompareMethod", WindowMode:=acDialog
' Is the form still open? If it's closed, we'll assume the user
wanted to cancel.
If CurrentProject.AllForms("frmCompareMethod").IsLoaded Then
intMethod = Forms!frmCompareMethod!optCompareMethod
DoCmd.Close acForm, "frmCompareMethod", acSaveNo
Else
MsgBox "Comparison cancelled."
Exit Sub
End If

If intMethod = 1 Then
' Do Method 1
Else
' Do Method 2
End If
'----- end of example code -----
 
Back
Top