Hello, I am having problems with the line I point to in the code below.
I have a main form (called MainForm, code given below), that calls another function called GetSearchResults(), which then in turn calls the function below.
The problem is that I have a global variable that I set in MainMenu, AFTER I call the function, but whenever the function InsertModuleText comes to that line, the variable I set in MainMenu gets reset.
Code:
Public Function InsertModuleText(strModule As Variant, strFormName As Variant)
Debug.Print "Function InsertModuleText()"
Dim frm As Access.Form
DoCmd.OpenForm strFormName, acDesign, , , acFormEdit, acHidden
Set frm = Forms(strFormName)
With frm
If .HasModule = False Then
.HasModule = True
End If
.Module.InsertText strModule ' <----This line!!
End With
DoCmd.Close acForm, strFormName, acSaveYes
End Function
for some reason, the line I point to above causes my variable(selectedForm) to be reset AND causes my array of string form names(formArray) to not work properly. The following is how I call this function:
Code in GetSearchResults to call InsertModuleText():
Code:
Dim formName As String
For Count = 1 To UBound(moduleArray)
formName = formArray(Count)
Call InsertModuleText(moduleArray(Count), formName)
Next Count
Any Idea about why this is making my variable selectedForm behave in that way?
This will help:
Order of Events:
- User Opens MainForm
- User Clicks 'Search'
- Search_Click() sub calls GetSearchResults()
- GetSearchResults() calls function InsertModuleText()
- Control returns to GetSearchResults()
- formArray is filled and control returns to Search_Click() in MainMenu
- selectedForm is set to 1
- User Clicks NextForm
- the value of selectedForm is outputted
MainForm Module Code:
Code:
Private Sub Search_Click()
checkResults = GetSearchResults(SearchQuery, formArray)
If (checkResults = True) Then
selectedForm = 1 '<--selectedForm set = 1
End if
End Sub
Private Sub NextForm_Click()
MsgBox selectedForm '<----gives 1 if InsertText line is commented out
'-----but gives 0 if InsertText line is uncommented
'-----this means the variable is being reset if InsertText
'-----is not commented out
End Sub
Thanks!!!
ÃaÃeVi£