Code flow after opening form in VBA

Domski74

Registered User.
Local time
Today, 21:06
Joined
Jan 29, 2009
Messages
18
Hi All

I have some code that works fine in Access 2000 but not in 2007, it's from lebans HTML editor (if you're familiar), it goes like this:

Code:
Private Sub cmdEditHMTL_Click()
On Error GoTo Err_cmdEditHMTL_Click
If IsNull(Me.testmemo) Then
    Me.testmemo = ""
End If
DoCmd.OpenForm "frmSHTMLeditor", acNormal, , , acFormEdit, acDialog, Me.testmemo
' For now I'm just using a Public Variable to hold the
' edited contents of the testmemo control.
' I'll encapsulate everything in the next release.
'docmd.OpenForm f,acNormal,,,acFormEdit,acDialog ,acWindowNormal
If Len(strHTML & vbNullString) > 0 Then
Me.testmemo.value = strHTML
End If
Exit_cmdEditHMTL_Click:
    Exit Sub
Err_cmdEditHMTL_Click:
    MsgBox Err.Description
    Resume Exit_cmdEditHMTL_Click
    
End Sub

In Access 2003 the code stops running on the open form line and continues when the opened form is closed, this is as it was designed. When I convert this to Access 2007 the form is opened but the code continues to run and then therefore doesn't get run when the form is closed?

Please can anyone advise why Access 2007 is behaving like this and is there a way around?

Thanks
 
not sure without checking, but you could just add this after the openform statement - and this will definitely wait.

i use this approach generally as it means you can manage the "popup" form as a normal form, and therefore resize and move it.


Code:
while isopen("your form name")
   doevents
wend

and then you need this function

Code:
Function IsOpen(strName As String, Optional objtype As Integer = acForm)
    IsOpen = (SysCmd(acSysCmdGetObjectState, objtype, strName) <> 0)
End Function
 
You say it works in Access 2003.

But it raises an error if Me.testmemo is Null.

Me.testmemo must be capable of being Null else this code is redundant: -

Code:
    If IsNull(Me.testmemo) Then
        Me.testmemo = ""
    End If

Me.testmemo seems to be a control on your form because if Me.testmemo is a declared Public Variant, and not assigned a value, it would be Empty not Null. Also, if it is a Public Variant then Me.testmemo.Value = strHTML would fail.

So, if Me.testmemo is Null then assiging a ZLS to it could still mean it’s Null when passed as OpenArgs and would raise an error in Form frmSHTMLeditor.

It therefore seems that there must be some error handling in Form frmSHTMLeditor that handles the passed Null and that code could shutdown that Form.

The line of code: -
DoCmd.OpenForm "frmSHTMLeditor", acNormal, , , acFormEdit, acDialog, acWindowNormal
actually passes a constant of 0 so I don’t know why Stephen Lebans would do that, if he did, because passing a hard coded constant should not be required.

So, which line of code is yours and which line is Stephen’s? : -
DoCmd.OpenForm "frmSHTMLeditor", acNormal, , , acFormEdit, acDialog, Me.testmemo
or
DoCmd.OpenForm "frmSHTMLeditor", acNormal, , , acFormEdit, acDialog, acWindowNormal

If indeed there is a difference between how Access 2003 and Access 2007 handles it we should try to track down the reason.

-------

I think we need to see how OpenArgs is handled in Form frmSHTMLeditor.

Chris.
 

Users who are viewing this thread

Back
Top Bottom