Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Posts
    240

    Unanswered: Global variables

    Hi,

    I am having difficulty populating a few global variables I have created, hopefully someone can help me.

    I have created a couple of modules, which all require the same value so I created a global variable in the first of my modules to run under General Declarations:

    Code:
    Option Compare Database
    Option Explicit
    
    Global gstrTableName1 As String, gstrTableName2 As String
    Within this module is a function where I set the value for the variables:

    Code:
        gstrTableName1 = "Prior_Qualification_" & rsQuery![COURSE]
        gstrTableName2 = "Predicted_Attainment_" & rsQuery![COURSE]
    Part of the value is from a recordset I am using.

    Within the function are various calls to the other modules to create tables and insert data, but whenever I specify the global variable in these modules I always get an empty string back.

    Can anyone help?

    Thanks

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    what happens if you put a watch on those lines (click the grey bar to the left of then line, and you should see a purple dot)
    what value is in rsQuery![COURSE]
    where are you setting it

    have you proved that you have got a valid value in rsQuery![COURSE]
    have you proved that you are not overwriting that value somewhere

    ...its one of the reasons why global values are NOT a good idea, unless you have to use them.. and I suspect you dont have to in your app.. you are 'just' choosing to. if you are setting theses values based on data from a db table then you can get those values as and when required and not use globals at all for this.

    globals are a necessary evil in some, not all apps. but you can get round it by carefull use of classes and functions... if for no other reason if you restart code after a debug then you cannot rely on those values being valid. if you put them in a function or class,, you can check if the fucntion / classes vlaues are valid and if not recreate/refresh them as required)
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Just an idea - what happens if you change your variable declarations to:
    Code:
    Option Compare Database
    Option Explicit
    
    Public gstrTableName1 As String
    Public gstrTableName2 As String
    George
    Home | Blog

  4. #4
    Join Date
    Sep 2005
    Posts
    240
    Managed to get it working now, forgot that I'd changed the name of the function so when calling it, it wasn't running.

    Thanks for the tips and alternate solution, will keep that in mind for the future.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •