Solved popup & modal

unfortunately the demo did not work when i tested it.
i modified the code (VBA) in "Open Form1 (Modal)" button
to somewhat make it stop.
I think I'm stuck with the form the way it is.
I might have to write a loop around the buttons, or the form, that goes nowhere until a button is clicked.
I have implemented Arnelgp"s code, with the module and without.
The form is accepting "modal on" but is still not stopping program flow.

Can there be some peculiar behaviour in the "Forms.Modal" property, which should stop program flow.
I have been through all the options and cannot see anything that might change this behaviour.

Code:
  Private Sub Form_Open(Cancel As Integer)
    If Me.OpenArgs & "" = "dialog" Then MakeFormDialog Forms("Messenger")
End Sub

Also the title bar is still visible but is now white.

Screenshot_7.jpg
 
i updated the Attached db and is now Not using any API. pls download it again.
 
As a matter of interest, I've just created a blank form and set modal on is blocking program flow.
I will rebuild the form and see what happens.
I will also try Arnelgp"new code.
I offer my thanks and gratitude to all.
Watch this space.
John
 
I've just created a blank form and set modal on is blocking program flow.
That surprises me. I'll have to try it out. Or, if you could post a sample db, that would be great.
 
A simple work around.
The form is now popup on modal off and opened with
Code:
Public Function Messenger() As Boolean
    DoCmd.OpenForm "messenger"
    Messenger = bYN
End Function

I have modified the form's code to become

Code:
Option Compare Database
Option Explicit
Private bOut As Boolean

Private Sub btnNo_Click()
    bOut = True
End Sub

Private Sub btnOK_Click()
    bOut = True
End Sub

Private Sub btnYes_Click()
    bOut = True
    bYN = True
End Sub

Private Sub CloseMe()
    Do
        DoEvents
    Loop While Not bOut
End Sub

Private Sub Form_Load()
    bYN = False
    getWidth
    Me.btnMessage.Caption = strMessage
    Me.btnOK.Visible = IIf(bOK = True, True, False)
    Me.btnNo.Visible = IIf(bOK = False, True, False)
    Me.btnYes.Visible = IIf(bOK = False, True, False)
    Me.imgCritical.Visible = IIf(strImage = "C", True, False)
    Me.imgInformation.Visible = IIf(strImage = "I", True, False)
    Me.imgExclamation.Visible = IIf(strImage = "E", True, False)
    If strImage = "C" Then
        Me.btnMessage.ForeColor = RGB(0, 0, 0)
        Me.btnMessage.BackColor = RGB(255, 253, 25)
        Me.btnMessage.HoverColor = RGB(255, 253, 25)
        Me.btnMessage.HoverForeColor = RGB(0, 0, 0)
    ElseIf strImage = "E" Then
        Me.btnMessage.ForeColor = RGB(255, 255, 0)
        Me.btnMessage.BackColor = RGB(253, 0, 0)
        Me.btnMessage.HoverColor = RGB(255, 0, 0)
        Me.btnMessage.HoverForeColor = RGB(255, 255, 0)
    End If
    Me.Visible = True
    CloseMe
    DoCmd.Close acForm, Me.Name
End Sub

Previously the btn onclick events were closing the form

The sub "CloseMe" simply loops until a button is clicked. bOut reverts to true and the loop ends.
An essentially modal form without being modal.
QeD.

Screenshot_8.jpg

Once again, many thanks to all.
John
 
ahhhh, i see that it is closing because on the Load event you are really closing the form.
you can separate the closing from the Load event also:
Code:
Private Sub btnNo_Click()
    CloseMe
End Sub

Private Sub btnOK_Click()
    CloseMe
End Sub

Private Sub btnYes_Click()
    bYN = True
    CloseMe
End Sub

Private Sub CloseMe()
    DoCmd.Close acForm, Me.Name
End Sub

Private Sub Form_Load()
    bYN = False
    getWidth
    Me.btnMessage.Caption = strMessage
    Me.btnOK.Visible = IIf(bOK = True, True, False)
    Me.btnNo.Visible = IIf(bOK = False, True, False)
    Me.btnYes.Visible = IIf(bOK = False, True, False)
    Me.imgCritical.Visible = IIf(strImage = "C", True, False)
    Me.imgInformation.Visible = IIf(strImage = "I", True, False)
    Me.imgExclamation.Visible = IIf(strImage = "E", True, False)
    If strImage = "C" Then
        Me.btnMessage.ForeColor = RGB(0, 0, 0)
        Me.btnMessage.BackColor = RGB(255, 253, 25)
        Me.btnMessage.HoverColor = RGB(255, 253, 25)
        Me.btnMessage.HoverForeColor = RGB(0, 0, 0)
    ElseIf strImage = "E" Then
        Me.btnMessage.ForeColor = RGB(255, 255, 0)
        Me.btnMessage.BackColor = RGB(253, 0, 0)
        Me.btnMessage.HoverColor = RGB(255, 0, 0)
        Me.btnMessage.HoverForeColor = RGB(255, 255, 0)
    End If
    Me.Modal = True
    Me.Visible = True
End Sub
 
Last edited:
ahhhh, i see that it is closing because on the Load event you are really closing the form.
you can separate the closing from the Load event also:
Code:
Private Sub btnNo_Click()
    CloseMe
End Sub

Private Sub btnOK_Click()
    CloseMe
End Sub

Private Sub btnYes_Click()
    bYN = True
    CloseMe
End Sub

Private Sub CloseMe()
    DoCmd.Close acForm, Me.Name
End Sub

Private Sub Form_Load()
    bYN = False
    getWidth
    Me.btnMessage.Caption = strMessage
    Me.btnOK.Visible = IIf(bOK = True, True, False)
    Me.btnNo.Visible = IIf(bOK = False, True, False)
    Me.btnYes.Visible = IIf(bOK = False, True, False)
    Me.imgCritical.Visible = IIf(strImage = "C", True, False)
    Me.imgInformation.Visible = IIf(strImage = "I", True, False)
    Me.imgExclamation.Visible = IIf(strImage = "E", True, False)
    If strImage = "C" Then
        Me.btnMessage.ForeColor = RGB(0, 0, 0)
        Me.btnMessage.BackColor = RGB(255, 253, 25)
        Me.btnMessage.HoverColor = RGB(255, 253, 25)
        Me.btnMessage.HoverForeColor = RGB(0, 0, 0)
    ElseIf strImage = "E" Then
        Me.btnMessage.ForeColor = RGB(255, 255, 0)
        Me.btnMessage.BackColor = RGB(253, 0, 0)
        Me.btnMessage.HoverColor = RGB(255, 0, 0)
        Me.btnMessage.HoverForeColor = RGB(255, 255, 0)
    End If
    Me.Modal = True
    Me.Visible = True
End Sub
I don't think that will work. there is nothing to keep the form open
ahhhh, i see that it is closing because on the Load event you are really closing the form.
you can separate the closing from the Load event also:
Code:
Private Sub btnNo_Click()
    CloseMe
End Sub

Private Sub btnOK_Click()
    CloseMe
End Sub

Private Sub btnYes_Click()
    bYN = True
    CloseMe
End Sub

Private Sub CloseMe()
    DoCmd.Close acForm, Me.Name
End Sub

Private Sub Form_Load()
    bYN = False
    getWidth
    Me.btnMessage.Caption = strMessage
    Me.btnOK.Visible = IIf(bOK = True, True, False)
    Me.btnNo.Visible = IIf(bOK = False, True, False)
    Me.btnYes.Visible = IIf(bOK = False, True, False)
    Me.imgCritical.Visible = IIf(strImage = "C", True, False)
    Me.imgInformation.Visible = IIf(strImage = "I", True, False)
    Me.imgExclamation.Visible = IIf(strImage = "E", True, False)
    If strImage = "C" Then
        Me.btnMessage.ForeColor = RGB(0, 0, 0)
        Me.btnMessage.BackColor = RGB(255, 253, 25)
        Me.btnMessage.HoverColor = RGB(255, 253, 25)
        Me.btnMessage.HoverForeColor = RGB(0, 0, 0)
    ElseIf strImage = "E" Then
        Me.btnMessage.ForeColor = RGB(255, 255, 0)
        Me.btnMessage.BackColor = RGB(253, 0, 0)
        Me.btnMessage.HoverColor = RGB(255, 0, 0)
        Me.btnMessage.HoverForeColor = RGB(255, 255, 0)
    End If
    Me.Modal = True
    Me.Visible = True
End Sub
That doesn't work. There is nothing to stop the code running past the end sub of the load event.
Calling the loop from the load event effectively halts the flow.
John
 
Removing the docmd from the load event and placing it after the loop statement looks a bit tidier.
Code:
Private Sub CloseMe()
    Do
        DoEvents
    Loop While Not bOut
    DoCmd.Close acForm, Me.Name
End Sub
 
I'm curious what your doing that will take 20 minutes to complete.
How many jpgs are you dealing with?
 
I'm curious what your doing that will take 20 minutes to complete.
How many jpgs are you dealing with?
I wondered how long that question would take.
I am scanning about 14000 jpg files and the same number of nef files.
I recover the file name and the full path to each file using a recursive search.
If I search an external drive, that has a full copy, it takes about 30 seconds but connected by wireless to the university servers it takes about 20 minutes depending on the traffic volume to the server.
An ethernet connection is a bit faster, but not that much. It all depends on other traffic.
Curiously it takes about three times as long to scan the jpg's as it does to scan the nef's on the uni server.
 
I see you are allowing DoEvents in the loop. Whatever you do, don't remove DoEvents from that loop you showed us in post #28. Event code cannot interrupt other event code, so the only way your bOut variable gets set is because DoEvents allows it.
 
I see you are allowing DoEvents in the loop. Whatever you do, don't remove DoEvents from that loop you showed us in post #28. Event code cannot interrupt other event code, so the only way your bOut variable gets set is because DoEvents allows it.
That's exactly why it's in there.
 

Users who are viewing this thread

Back
Top Bottom