Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > BOOK: Access 2010 VBA Programmer's Reference
|
BOOK: Access 2010 VBA Programmer's Reference
This is the forum to discuss the Wrox book Access 2010 Programmer's Reference by Teresa Hennig, Rob Cooper, Geoffrey L. Griffith, Jerry Dennison; ISBN: 978-0-470-59166-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Access 2010 VBA Programmer's Reference 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 June 18th, 2012, 07:42 AM
Authorized User
 
Join Date: Jun 2006
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Question Public variable's 'lifetime' only module/procedure-level ?

Referring to page 152, the following code ( declarations ) which I hoped would retain the value of sSid, when another form opens, to be referenced there, doesn't....

[CODEOption Compare Database
Dim pin As Integer
' Get the full path and name of the current database
Dim db As DAO.Database
Dim rs, rs1 As DAO.Recordset
' for Staff_ID as filter on Main Form
Public sSid As Long
Dim strFullpath, strSQl As String
Dim Msg, Style, Title, Response
Dim c As Long][/CODE]

Any ideas ? ( probably something simple, I've overlooked, knowing me ... ) Thanks.
 
Old June 18th, 2012, 08:20 AM
Authorized User
 
Join Date: Oct 2010
Posts: 64
Thanks: 0
Thanked 16 Times in 16 Posts
Default

"when another form opens"

What exactly do you mean by this?

The variable should be accessible from the instance of the form where the variable is declared. So, if your form is named "myForm", retrieve your public variable like this. e.g.

MsgBox "sSid = " & Forms("myForm").sSid

HTH.

Malc.
 
Old June 18th, 2012, 10:17 AM
Authorized User
 
Join Date: Jun 2006
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Default

Many thanks. I see now, I simply treated it as if it were an available variable declared in the new form, i.e. TextBox.Text = sSid

Whereas in fact, I must reference the orginal form it was decalred in i.e.

TextBox.Text = Forms("frmMyForm").SSid
Thank you.





Similar Threads
Thread Thread Starter Forum Replies Last Post
public article - public articledetails _keysersoze_ BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 September 8th, 2007 08:38 AM
Running stored procedure from .adp module mantle51 Access VBA 1 August 13th, 2007 12:17 PM
CCommand Lifetime comdev2001 Oracle 0 November 29th, 2005 12:13 PM
CallByName from public module dbradley Pro VB.NET 2002/2003 0 July 16th, 2003 02:35 PM





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