Hi!
I'm trying to create a drop-down based Msgbox/Inputbox-like form for general purposes. When I try to modify the events using CreateEventProc / InsertLines, all of my instanced forms close abruptly.
I've tried this with both a form copied by CopyObject as well as with a new form created by CreateForm. Similar result.
The closest thread I found to this is at showthread.php?t=254881
A modified version of my code is below (it does reference the copied form's initialization function...)
When this code is run, the form is created/modified successfully, but all currently instanced forms close abruptly. (Which is half of the application! :banghead
Is this due to compilation issues (or something else that should be obvious)?
Any alternatives that would be more user friendly than a msgbox or inputbox?
Thanks in advance.
- Dunro
I'm trying to create a drop-down based Msgbox/Inputbox-like form for general purposes. When I try to modify the events using CreateEventProc / InsertLines, all of my instanced forms close abruptly.
I've tried this with both a form copied by CopyObject as well as with a new form created by CreateForm. Similar result.
The closest thread I found to this is at showthread.php?t=254881
A modified version of my code is below (it does reference the copied form's initialization function...)
Code:
Private Sub cmdReplace_Click()
Dim pTempFormName As String
Dim pInstanceNum As String
Dim mdl As Module, lineNum As Long
Const cnsModuleName = "cmdReplace_ClickOld"
Dim testObj As Object
pInstanceNum = Format(Now(), "yyyymmddhhmmss")
pTempFormName = "TEMP " & pInstanceNum & " Question"
On Error Resume Next
' Attempt to open the form... This should fail.
Set testObj = CurrentProject.AllForms(pTempFormName)
If Err.Number = 2467 Then
' Creates form, but does not open it yet.
On Error GoTo Exit_Error
DoCmd.CopyObject NewName:=pTempFormName, SourceObjectType:=acForm, SourceObjectName:="Form Question"
DoEvents
DoCmd.OpenForm formName:=pTempFormName, View:=acDesign, WindowMode:=acHidden
ElseIf Err.Number <> 0 Then
' ... debug code for other errors go here eventually.
Else
DoCmd.OpenForm formName:=pTempFormName, View:=acDesign, WindowMode:=acHidden
End If
Set mdl = Forms(pTempFormName).Module
lineNum = mdl.CreateEventProc(EventName:="Click", objectname:="cmdOK")
If lineNum > 0 Then
lineNum = lineNum + 1
mdl.InsertLines Line:=lineNum, String:="Call pResultGoto.cmdReplace_ClickPT2(documentID:=" & Nz(Me.Controls("txtID").Value, 0) & ",replacementType:=Me.cboAnswer.value)"
' mdl.InsertLines Line:=lineNum, String:="Msgbox ""Test.""" ' this code works, but Instanced forms still disappear.
End If
DoCmd.Close objectType:=acForm, objectname:=pTempFormName, Save:=acSaveYes
If tempCollection Is Nothing Then: Set tempCollection = New Collection
DoCmd.OpenForm formName:=pTempFormName
If childInstanceFrms Is Nothing Then: Set childInstanceFrms = New Collection
Call Forms(pTempFormName).init(parentInstanceCollection:=childInstanceFrms, visible:=True, question:="Why is this document being replaced?", resultGoTo:=Me)
Forms(pTempFormName).cboAnswer.RowSourceType = "Value List"
Forms(pTempFormName).cboAnswer.AddItem "1;Original uploaded in error."
Forms(pTempFormName).cboAnswer.AddItem "2;Original draft revised on the same date."
Forms(pTempFormName).cboAnswer.AddItem "3;Attached document was revised on a different date."
End Sub
When this code is run, the form is created/modified successfully, but all currently instanced forms close abruptly. (Which is half of the application! :banghead

Is this due to compilation issues (or something else that should be obvious)?
Any alternatives that would be more user friendly than a msgbox or inputbox?
Thanks in advance.
- Dunro