Question : Open form in acDialog command not working

I want to prevent msg's from appearing before form is fully opened. I tried the Window mode code below both in the On Open and / On Load events still without success.

For example when frmFilingDates is opened, I want to setfocus first on txtGetdateFiling field before any of the two msgboxe(s) gets launched.

Secondly, after adding the acDialog command, I am now getting, a Run-time error '2467'. "The expression you entered refers to an object that is closed or doesnt exist".

on.....

         Set rs = Me.RecordsetClone
            rs.FindFirst "QtrNo = " & iQQ & " AND YearNum = " & iYY

from the On Load Event code below:
' *******
Private Sub txtGetDateFiling_BeforeUpdate(Cancel As Integer)
' ************* Help needed here*******
    Dim strObjectName As String
    strObjectName = "frmFilingDates"
    DoCmd.OpenForm FormName:=strObjectName, datamode:=acFormAdd, windowmode:=acDialog
  ' ************* Help Area Ends*******

    Dim iQQ As Integer
    Dim iYY As Integer
    Dim rs As dao.Recordset
       
    'If date is blank and u want to throw an error then to this
    If IsNull(Me.txtGetDateFiling) = True Then
        MsgBox "Date is mandatory"
        Cancel = True
        Exit Sub
    End If
   
    If IsDate(Me.txtGetDateFiling) = False Then
        MsgBox "Invalid date entered"
        Cancel = True
        Exit Sub
    End If
   
    'Get current quarter/year based on system date
    iQQ = DatePart("q", Date)
    iYY = DatePart("yyyy", Now())

    'If current date is not last of last quarter
    If DateIsLastQuarterDate(Now()) = False Then

        'If quarter 1 then for previous quarter, we need to subtract the  year also
        If iQQ = 1 Then
            iQQ = 4
            iYY = iYY - 1
        Else
            iQQ = iQQ - 1
        End If
    End If
   
    'Date entered must be in grace period
    If GracePeriodValidation(Me.DateFiled, iQQ, iYY) = False Then
        MsgBox "Invalid Date"
        Cancel = True
    End If
End Sub

Answer : Open form in acDialog command not working

Bill

1. You had the Filing Date form set to open in the Startup options
Then, on the open event of the same form, you attemped to open the Filing Date form agian.

I simply commented out the code on the form that tries to open the form again.

Yes, the "dialog" style does not appear to have any relevance to your problem.

What you are looking for is the Mythical "OnAppear" event!
:)

It is funny:
The order of events for a form is
Open, Load, Resize, Activate, Current.

All of these events actually occur BEFORE the form is visible on the screen!
:)
So Yes, any messagebox triggred will appear BEFORE the form is visible.

So to correctly answer your question, NO, you cannot prevent a messagebox from appearing BEFORE the form is visible if you use the; Open, Load, Resize, Activate, or Current Events.


So without you having to explain to us the reason behind every line of code, perhaps the simplest way around this is might be to move any of the "Validation code" (Any code that might produce a messagebox) to a button Click event.

(make the Default View of the form "Contiouous Form" and move all the controls close together (To simulate your Datasheet Veiw)

I have posted a sample here:
http://www.ee-stuff.com/Expert/Upload/getFile.php?fid=1733

I would like you and puppydogduddy to review it and submit any comments/questions you may have.

Jeffrey Coachman
Random Solutions  
 
programming4us programming4us