Results 1 to 5 of 5
  1. #1
    Larryg is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    50

    Global variable for recordcount

    Hello All;

    I have a form (form#1) that creates a recordset. That recordset populates another form (form#2). I want the recordcount (MyRecordCount) generated from form #1 to be available to use on form#2 after form #1 closes.
    I have tried:
    Option Compare Database
    Public MyRecordCount as Long
    Option Explicit
    on form #1
    and tried using the MyRecordCount value on form #2, but I get an error of "The expression you entered refers to an object that is closed or doesn't exist".
    MyRecordCount displays just fine on form #1.



    Form#1 has been loading the records onto form#2 as intended, I just need the total recordcount of the recordset to be available for a display on form #2. I have also tried the TempVars method also with no luck. I suspect I'm not putting the code in the correct areas.
    I can't use a rs.MoveLast rs.MoveFirst procedure again because I don't want to lose my place in the recordset.
    (On form#2 the user enters data, then saves the record, and I have a MoveNext command to get the next record. The order of the "Next" record matters due to date/time priority of the next record.)

    Any suggestions?

    Thanks...

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    You can pass variables like your recordcount on the openform function as a parameter


    Sent from my iPhone using Tapatalk

  3. #3
    Larryg is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    50
    Quote Originally Posted by andy49 View Post
    You can pass variables like your recordcount on the openform function as a parameter


    Sent from my iPhone using Tapatalk
    So are you indicating that it can not be a Global variable? And doing it your way, are you talking OpenArgs?

    Thanks...

  4. #4
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Open Args is what I was referring to


    Sent from my iPhone using Tapatalk

  5. #5
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Are you declaring your global variable through the form? It can only be accessed whilst the form is open.

    It's better to declare a global variable through a module

    See attached.




    Sent from my iPhone using Tapatalk

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Global Variable
    By gtg430i in forum Programming
    Replies: 11
    Last Post: 03-10-2014, 05:00 PM
  2. Can't See Global Variable
    By CementCarver in forum Programming
    Replies: 12
    Last Post: 09-19-2013, 12:28 PM
  3. How to use global/public variable
    By mrbabji in forum Programming
    Replies: 7
    Last Post: 05-18-2013, 10:08 PM
  4. Global variable
    By ramdandi in forum Queries
    Replies: 3
    Last Post: 12-18-2011, 01:01 AM
  5. Replies: 4
    Last Post: 07-14-2011, 12:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums