Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display form/message whilst processing code

Status
Not open for further replies.

SteIT

Programmer
Nov 22, 2007
18
GB
Using access2003. Is it possible to display an access form or message box, but continue runnning vba code ?

After user adds data to a form, I process a number of word documents. I wish to display a message informing user that documents are being created. Once completed, remove the form/message box and display message informing Job complete.

Thanks

Steve
 
How are ya SteIT . . .

Using a [blue]non-modal[/blue] form to display your message . . . [blue]Yes![/blue]

Using an [blue]access MsgBox[/blue] (which is modal). . . [blue]No![/blue]


Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Hi Steve,

Not sure if this what you are trying to do, but just before the code that process the word documents, you could put a message box stating something like:

Code:
msgbox "Documents are being created, once finished another message will appear", vbOkOnly, "Some title"

Then once its finished bring up another message box saying it has.

Either that or you could use a form in place of the first message box, and before the process code have the form opened, and take off all the close, min/max buttons etc so the user can't close/move it. Then when its finished have the form closed and a message box come up saying it has finished.

Hope this helps,

Andrew
 
:) Thanks for the replies.

The problem with using a message box is the code stops until the user hits the okay button, I would like to keep a message displayed until the code has finished (as the updates to the word docs are done with visible=false).
Once completed I display a message saying "Completed and saved in <path>".

Regatds

Ste
 
Ok, but does the code run if you opened up a form instead (in which the form looks like a message box)?

Andrew
 
To All . . .

I repeat:
[blue]Using a [purple]non-modal form[/purple] to display your message . . . [purple]Yes![/purple]

Using an [purple]access MsgBox[/purple] (which is modal). . . [purple]No![/purple][/blue]
[blue]SteIT[/blue] . . . perhaps a [blue]Progress Bar[/blue] will do? . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
TheAceMan1, I don't know what a non-modal form is without lookin it up so I put my input in anyway, if its the same as what I suggested, then credit goes to you!

Andrew
 
No, if I open another form (with a message on the form) the code stops until the new form is closed
 
Ok, ive never implemented a progress bar as TheaceMan1 suggested before, but that sounds like the way forward for you tbh.

Andrew
 

Thanks TheAceMan1


Using a non-modal form to display your message . . . Yes!

Using an access MsgBox (which is modal). . . No!

I have tried displaying a form as modal and non-modal, but the code stops until the form is closed.

Do you have an example ?

Thanks

SteIT
 
I assume you want the message to stay up until the code has finished running.

You could create a Modal (Means the form stays on top or in other words can not be moved behind another form) form and move your code you want to run in that form. When it's done, have the form close itself.

Or you can place a normally hidden label in the center of the form, before you run the code, make it visible and when the code is done, hide it again.
 
SteIT . . .

Either the forms [blue]PopUp[/blue] and [blue]Modal[/blue] properties are set to Yes, or your opening the form modal in VBA . . .
Code:
[blue]   DoCmd.OpenForm "YourFormName", acNormal, , , , [purple][b]acDialog[/b][/purple][/blue]
. . . or both!

Be sure thr forms [blue]Modal[/blue] property is set to [blue]No[/blue], and if your opening the form thru VBA, open the form normal:
Code:
[blue]   DoCmd.OpenForm "YourFormName"[/blue]
Have you looked at the [blue]Modal[/blue] property in Help?

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
To All . . .

[blue]It appears my origional post just doesn't make sense![/blue] [surprise]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
CaptainD . . .

Your option is perfectly legit! [thumbsup2] . . . I just posted a little later than you . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
I use the code below to open a form called frmWait. This does not stop the code running.

You open the form with

ap_SetWorkingState "Your Message", True

and close with

ap_SetWorkingState ,False

frmWait has the following controls

lblMessage which is used to display the message set in the call.

Hope this helps and can be understood as it does exactly what you want.


Code:
Public Sub ap_SetWorkingState(Optional sMessage As String = "Working, Please Wait......", Optional aState As Boolean = True)
On Error GoTo ErrHandler

If aState = True Then
    If (Not ap_FormlsOpen("frmWait")) Then
        ap_OpenForm "frmWait"
    End If
    DoCmd.Hourglass True
    Forms("frmWait").Form.lblMessage.Caption = sMessage
    Forms("frmWait").Form.Repaint
Else
    ap_CloseForm "frmWait"
    DoCmd.Hourglass False
End If

Exit Sub
ErrHandler:
    ' Insert error handler
Exit Sub
End Sub

' ###################################################################################

Function ap_FormlsOpen(strFormName As String) As Integer
On Error GoTo ErrHandler

Dim frmCurrent As Form

For Each frmCurrent In Forms
    If frmCurrent.Name = strFormName Then
        ap_FormlsOpen = True
        Exit Function
    End If
    
    Next frmCurrent
    
Exit Function
ErrHandler:
    ' Insert error handler
Exit Function
End Function

' ###################################################################################

Function ap_OpenForm(sFormName As Variant, _
                       Optional nStat As Variant = acNormal, _
                       Optional sFilter As String = "", _
                       Optional sWhereClause As String = "", _
                       Optional nMode As Variant = acWindowNormal, _
                       Optional sOpenArgs As String = "")
                       
On Error GoTo ErrHandler
                       
Dim sFName As String
    
    If IsObject(sFormName) Then
        sFName = sFormName.Name
    Else
        sFName = sFormName
    End If
    
    If ap_FormlsOpen(sFName) Then
        Forms(sFName).Repaint
    Else
        DoCmd.OpenForm sFName, nStat, sFilter, sWhereClause, , nMode, sOpenArgs
    End If

Exit Function
ErrHandler:
    ' Insert error handler
Exit Function
End Function

' ###################################################################################

Function ap_CloseForm(sFormName As Variant)

On Error GoTo ErrHandler

Dim sFName As String

    If IsObject(sFormName) Then
        sFName = sFormName.Name
    Else
        sFName = sFormName
    End If
    
    If ap_FormlsOpen(sFName) Then
        DoCmd.Close acForm, sFName
    End If
    
Exit Function
ErrHandler:
    ' Insert error handler
Exit Function
End Function

' ###################################################################################

 
CaptainD said:
Means the form stays on top or in other words can not be moved behind another form

Thankyou for your explanation of Modal.

Andrew
 
Sorry left the code on the form off the above post

Code:
Option Compare Database
Option Explicit

Private Const smodule As String = "frmWait"

Private Sub Form_Load()

On Error GoTo ErrHandler

    DoCmd.MoveSize , , Width, Detail.Height

Exit Sub

ErrHandler:

    Call ErrMsg("Form_Load", smodule, Error, Err)
    
Exit Sub

End Sub

 
:-D Thanks MikeC14081972

This does do what I asked for.

Thanks all for the responses.


Regards

SteIT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top