Open Form Code

A

Andy

Hi there, I have the existing code already linked to a click button event to
trigger an import dialog box and import process.

What I would like to do is insert some code around this to open 'Form A' as
the first step and to close the form as the last step within the code. The
imports are often half a million records and the form is a 'Database busy'
form to make sure the user understands to just be patient!

---------------------------------------------------------------------------------------------

Private Sub Command141_Click()

Dim strFilter As String
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, _
"txt Files (*.txt)")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select the file to import...", _
Flags:=ahtOFN_HIDEREADONLY)
If Len(strInputFileName) > 0 Then
DoCmd.TransferText acImportFixed, "Outpatient CMDSOP
Import/Export", "CMDSOP", strInputFileName, False, ""
X = MsgBox("The Outpatient CDS file has now been imported into the
database", 64, "CDS and PbR Database")
End If

End Sub
 
D

Dennis

Well, there's a fundamental problem in doing that. Once the application
starts processing a large amount of data, screen updates have the lowest
priority of anything windows (and Access) does. I've found that even though I
issue the openform command, the form's actual appearance on-the-scene (so to
speak) never happens. So what I did to get around that is create a form that
essentially says "Processing, please be patient".

I set that form's VISIBLE property to FALSE (in form deisgn mode). Then I
open that form when the application first starts. That way, it's already
available. Then, instead of the openform command, I simply set the form's
VISIBLE property to TRUE immediately prior to executing the code. I then set
the VISIBLE property back to FALSE at the end of code execution. Works like a
charm.

Alternatively, you can write to the STATUS line at the bottom of the Access
pane.
 
D

Dale Fye

Dennis,

I've generally found that if you issue a DoEvents command after opening the
form, it will load the form and make it visible before executing the other
code.

Andy,

You should be able to preface the Docmd.Transfer text line with code
similiar to:

Docmd.openform "formName"
DoEvents

Don't use the Dialog mode when opening the form, or none of the code that
follows that will occur until the form is closed.

Rather than using the messagebox after the import, you might want to
consider putting a label control on "Form A" and changing the caption of that
label when the import completes. You could also have an OK button on that
form, hidden initially, that you make visible when the import is complete.
Something like:

Docmd.TransferText ....

Forms("Form A").lbl_Message.Caption = "The outpatient CDS file has ...."
Forms("Form A").cmd_OK.Visible = True

Then, in the Click event of cmd_OK, close the form. Make sure to set the
CloseButton and Control Box properties of "Form A" to false so the user
cannot close the form except via the OK button.

HTH
Dale
 

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