Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 8th, 2005, 08:25 AM
Authorized User
 
Join Date: Aug 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Module.InsertText affecting unrelated variables!



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£
__________________
ÐaÐeVi£
 
Old October 16th, 2005, 12:43 AM
Friend of Wrox
 
Join Date: Jul 2005
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default


You might try using a textbox on your Main Form to hold the data and reference this and not the global variable.



Boyd
"Hi Tech Coach"
Access Based Accounting/Business Solutions developer.
http://www.officeprogramming.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort unrelated strings johngavin XSLT 7 January 8th, 2008 07:49 AM
Option Group Variables (from Form to Module) emanuele.musa VB How-To 1 July 20th, 2007 03:58 PM
Class module variables in VB6 maxpotters Pro VB 6 2 September 18th, 2005 12:15 PM
How to remove rowguid without affecting ids bful SQL Server 2000 2 November 28th, 2003 12:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.