Global Variables Lose Values

Jun 7, 2005

i have a form (frm1) and subform (sfrm1) that when a room number is double-clicked in the subform another form (frm2) and subform (sfrm2) loads. frm1 has building info and frm2 is used for inspection info. if a room has never been inspected then when frm2 loads the field [room] will be empty. however, after the first inspection the room number is obviously entered for frm2.

so i have created a global variable that holds the value of [lab_room] from frm1 and is supposed to use this value on frm2 if the room has never been inspected - ie, [room] is null. however, the value of intRoom (global variable) is lost after is leaves frm1 and goes to frm2. below is my code:



modGlobal (module with global variables declared)
Option Compare Database

Global intVar As Variant
Global intRoom As String

Private Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid) As Long

Private Type GUID 'Memory structure used by CoCreateGuid
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type

Private Const S_OK = 0 'Return value from CoCreateGuid

frm1 subform double click event
Private Sub Form_DblClick(Cancel As Integer)
On Error GoTo Err_DblClick

Dim stDocName As String
Dim stLinkCriteria As String
Dim stMsg As String

'if the user double clicks on an area that has no lab_id associated with it
'prevents a null value for lab_id
If IsNull(Me!lab_id) Then
stMsg = "There is no lab associated with this room."
intRes = MsgBox(stMsg, vbOKOnly + vbExclamation, "Error - No Lab Selected")
GoTo Exit_DblClick
End If

'opens lab forms associated with this lab_id
intVar = Me!lab_id
intRoom = Me!lab_room
stDocName = "ehs_lab_safety_surveys"
stLinkCriteria = "[lab_id]=" & "'" & intVar & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
[Forms]![ehs_lab_safety_surveys].Form.RecordsetClone.Find ("lab_id = '" & intVar & "'")

DoCmd.Close acForm, "copy_lab_search_by_bldg"

Exit_DblClick:
Exit Sub

Err_DblClick:
MsgBox Err.Description
Resume Exit_DblClick
End Sub

frm2
Private Sub Form_Load()

Dim strNewguid As String

'checks for null values of lab_id, room, id and safety_survey_date. if they are
'null or empty a value is inserted.

If IsNull(Me!lab_id) Or (Me!lab_id = "") Then
Me!lab_id = intVar
End If

If IsNull(Me!room) Then
Me!room.Value = intRoom
End If

If IsNull(Me!safety_survey_date) Then
Me!safety_survey_date = Date
End If

If IsNull(Me!id) Or (Me!id = "") Then
Set x = CreateObject("Scriptlet.TypeLib")
strNewguid = Left(x.GUID, 38)
Me!id.Value = strNewguid
End If

DoCmd.Maximize

End Sub



can anyone see why the value is being lost from frm1 to frm2? i'm ripping my hair out trying to figure this one out....

View Replies


ADVERTISEMENT

Global Variables

Feb 13, 2006

I have an access form called forma. It has a command button. When I click a command button, FormB opens up and FormA closes. The FormB also has a command button. When I click the command button of Form B, it closes and opens FormC. Like this there are total 30 forms. What I need is. I want to count the no. of clicks of the command button in total. Actually each button is a correct option of A multiple choice question. I tried to declare a public Variable called total in the declareation of the first form and tried to use it directly in the succeding forms. It does not capture the values. How can I increase the value of the varialbe declared in the first form even after the form closes and capture till end. Actually I also should be able to send the value in a table. Please Help Me.!

View 2 Replies View Related

Global Variables As Criteria

Dec 5, 2005

Anyone know how to reference a global variable as criteria for a query?

I am currently using invisible text boxes on an intermediary form as criteria for my query and it works fine, but this solution seems inellegant and I'm looking for something a little smoother. I just need the correct syntax to reference a variable in the criteria section of a query.

Thanks!

View 1 Replies View Related

Queries :: Global Variables To Be Used In SQL String

Sep 12, 2014

I have a number of global variables set when a user logs into my application which i want to use in an SQL string to record these in a table however im not sure how i go about it i know simply inserting the defined names in the SQL wont work.

Is there a way to define these in global functions instead?

View 1 Replies View Related

Modules & VBA :: Open Recordsets As Public Or Global Variables

Apr 22, 2015

Is there any way of opening recordsets as public or global in a form? E.g. if i do something like

Set rs = db.OpenRecordset("TblCustomers", dbOpenSnapshot, dbReadOnly)

the variable rs should be available in all the private sub i have on that form, and i should be able to access records without opening database/ record sets for individual subs.

View 6 Replies View Related

Modules & VBA :: Define Global / Public Variables From A Table?

Sep 4, 2013

I would like to declare Global or Public variables from a table so they can be added to or edited easily. I had the following function to do this with Alpha Five but at the moment my lack of knowledge of Access VBA is making this task difficult.

Here is the function that I use in Alpha:

FUNCTION udVars AS A (udTabName AS C )
dim codeStr as c
t=table.open_session(udTabName,file_ro_shared)
t.fetch_first()
while .not. t.fetch_eof()

[Code] ....

It opens a table reads in the records and then makes them into a string the string would look something like this:

"Public EuroRate as Single = 0.885"

I would then need to use this string to declare the variables but not sure what command to use - I was looking at the Eval function last night but couldn't get this to work...

The table would hold strings for all the above so you would have:

My_Var (variable name)
My_Typ (type of variable e.g. Single)
My_Val (value e.g. 0.885)

The table would hold as many variables as required, some would be dates, some paths for making directories and some would be numbers.

View 6 Replies View Related

Setting A Couple Of Global Values?

Oct 5, 2015

Right so I have a database which is split. I have two values which are universal and only change occasionally so I don't want them in a table against every record in the database. I have currently set them up as globals in a module I want to set it up so I can draw the values in from the backend database rather than having to edit every single copy of the front end each time.

View 7 Replies View Related

Sharing Values/Variables Between Forms

Jun 26, 2007

Is it possible to access the values on one form and use them on another? For example, I have heard that the code might look something like this:

Form1.Text1.Text

When I've tried this, it doesn't work. Someone mentioned something about declaring them as Public, but they're not variables, they're actual record values on another form. Any suggestions?

Thanks!
Mike

View 8 Replies View Related

Don't Lose Position From A Entry.

Jul 21, 2005

I have a Button, which update various data into a table in a form. If i called a requery (me.requery) then, the the coursor move up to the first entry.

Whats the problem with this?
Andi

(Sorry for my bad englisch)

View 2 Replies View Related

Big Trouble: Lose Data In Synchronizing

Oct 22, 2004

This is very bad. We're losing data changes when we run a synchronize on an Access database.

A client wanted to use replication so he could have several people using the same database and then update everyone's changes. (It turns out that he's not used that feature.)

The client was unable to get the replica to work on his machine, so he uses the master version.

Instead, we've used replication to allow me to make changes in the database structure while he makes changes in the data. (Obviously, it would have been better to split the database in two parts, but it's too late for that now.)

Here's my process when I need to update his copy:
1. Synchronize between my master and replica.
2. Copy master to CD-R. (We're not on a network.)
3. Synchronize between client's master and replica.
4. Send a copy of master to client.
5. Open my new version of master on the client's computer and synchronize with his replica copy.

When we do that many of his recent changes disappear.

Why is that? They don't even show up as conflicts.

What are we doing wrong? Are we totally abusing the concept of replication or what??

I'm stumped. I appreciate any suggestions or thoughts.

View 2 Replies View Related

Verifying Data In A Text Box When It Lose Focus

Jan 17, 2012

I have a form and one of the text fields I need to verify against data in a table. I think the best way is to check the field once it loses focus on that text field. If the data is not in the table then the user is prompt with a msg "Invalid data, Please try again". I'm using Access 2010 to develop. I need query to run the validation.

View 1 Replies View Related

Subform Run From Query, Lose's Filter When Adding Data.

Mar 14, 2006

I have a form which is linked to a query. The main form which calls this form sets the filter for the query. This works fine and I can navigate all the filtered records.

The problem is when I go to add a new record the filter information goes away.

For backround this is DB for project information. The user clicks a button to view notes on the project. The notes are stored in a different table and the project_id is the common field which links the two together. I want this to function where the user can open the subform read the notes and add a new one if needed.

View 1 Replies View Related

Forms :: How To Lose Focus From A Subform When Selecting Record

Dec 17, 2014

I have a form, with a subform,

When a user selects a record from the subform i use this to view the record in the main form

Private Sub Txt_Support_Name_Click()
DoCmd.ApplyFilter , "ID =" & Me.ID
End Sub

However when i select the record from the subform, it populates the form as required, however then the top record of the subform is highlighted.

Any way to either - highlight nothing, or highlight the selected row?

View 4 Replies View Related

General :: Saving Links - Combobox Not Lose Data?

Jul 31, 2012

I'm saving links to a combobox in a form, but each time I close out of the form and reopen it the Combobox doesn't keep the list of data I entered before and only keeps the last selected one in its drop down menu.

Is there a way to make the Combobox store/keep the data?

View 14 Replies View Related

Global Var

Apr 15, 2008

Quick question that I suddenly have gotten stuck on: How do I use a global var in the query builder grid as a parameter? It keeps putting quotes around it - ?!

View 14 Replies View Related

Global Rename

Jul 20, 2005

Is there a way to rename all my queries at teh sam time.

View 2 Replies View Related

Global Name Query

Mar 10, 2008

I need to creat a global Name Query. I have 4 Tables. Each table has a Unique Name and a name Field, Such as:

Table: Parents
Field: Parents name

Table: Students
Field: Student Names

I need to Create a Query That just has one Field Call Name.

And i need it to pull all the names from the name field in all 4 tables.

PLease help.

View 1 Replies View Related

Global Variable Use

Sep 23, 2005

I have 3 different forms, each belonging to 3 different tables. The user is required to enter data on form 1 then form 2 & then form 3. The records on all the 3 forms has to be attached to the same primary key.
The problem is that the user has to enter the same primary key for each form.
I want to be able to carry the primary key entered on form 1 to form 2 and form 3, so that the user does not have to type it 3 times. How can i accomplish this ? Can i call the last primary key entered on table 1 and automatically pop it up on form 2 & 3 every time form 2 & 3 load?
Thanks

View 2 Replies View Related

Global Change For End Users

Jun 20, 2006

All my users have a shortcut on there computer to the database.

What I like to do is create a new shortcut.

But I don't want to go to each users desk and change the old one to to new one.

There should be someway that you can do a global change.

Anybody have an idea how this can be done?

View 3 Replies View Related

Global Search And Replace

Dec 13, 2006

Hi,
My company has renamed a product. I want to find all the records in all the tables in my database that might have the old name, and replace with the new name. What's the easiest way to do this?

I don't really want to have to manually open each table and do a find.

I can write code to go through all the tabledefs and do a find on each one, but the only way I know to do that is by telling it the field name, and field names where the product name might exist vary.

I suppose I can tell it something like
for each TD in tabledefs
for each F in td.fields
{search and replace}
next f
next t

Is this really the best way? I have a program called SpeedFerret, which I thought would do this, but it apparently only searches the table names, not the actual records in the table.

View 4 Replies View Related

Referencing A Global Variable

May 18, 2005

I am trying to use a global variable in a dlookup but get an error when i try and run the form

Here is the code:

VUserID is my Global Variable.

Private Sub Form_Open(Cancel As Integer)

Dim UsersName As String

Me.WelcomeBox = UsersName

UsersName = DLookup("[Name]", "tbl Password", "[username] = vUserID")

End Sub

Any Ideas

View 1 Replies View Related

Global Variable Question

Oct 2, 2006

Got a problem trying to reference a global variable in the control source of a text box.

If i do a DLookup when the form opens and have the text box value = the result it works fine ie

Private Sub Form_Open(Cancel As Integer)
Text2.Value = DLookup("UserName", "Users", "[UserID]= " & MyUserID)
End Sub

Where MyUserID is the global variable.

if i put
= DLookup("UserName", "Users", "[UserID]= " & MyUserID)
in the control source of Text2 i get #Name? as a result and if i input
= DLookup("UserName", "Users", "[UserID]= 1")
i get the correct result.

As a test i tried to have the control source = my global variable, of another text box control source with the same result.

It looks like i can only reference my global variable within the VB and not in the forms control sources. Is this correct or can you referece the Global variable in the control source.

Shot

View 6 Replies View Related

Using A Global Variable In Outside Query?

Dec 15, 2004

i am having trouble with my where clause.. ca someone take a peek please..

Note: gID is defined globally as integer and tblCheckReq.ID is defined as an auto-number (in table). Thanks in advance!

SELECT tblCheckReq.UserName, tblUsers.UserDept, tblCheckReq.PaymentMethod, tblCheckReq.PaymentDueDate, TRIM(tblCheckReq.Company & " " & tblCheckReq.TaxType & " " & tblCheckReq.PaymentType) AS DISTDETAIL, tblCheckReq.TaxYear, tblStateTaxDepts.To, tblStateTaxDepts.Street, Trim(tblStateTaxDepts.City & ", " & tblStateTaxDepts.State & " " & tblStateTaxDepts.Zip) AS FULLADDR, tblCheckReqAmtsToAccts.GLAccountNo, tblCheckReqAmtsToAccts.Amount, tblCheckReq.ID, tblCheckReq.Approvedby, tblUsers.SalaryCode, tblCheckReq.Date, tblStateTaxDepts.Dept, tblStateTaxDepts.To, tblCheckReq.TaxYear, tblUsers_1.SalaryCode, tblCheckReq.Company, tblCheckReq.TaxType, tblCheckReq.PaymentType
FROM (((tblCheckReq INNER JOIN tblCheckReqAmtsToAccts ON tblCheckReq.ID=tblCheckReqAmtsToAccts.ID) INNER JOIN tblUsers ON tblCheckReq.UserName=tblUsers.UserName) INNER JOIN tblStateTaxDepts ON (tblCheckReq.TaxType=tblStateTaxDepts.TaxType) AND (tblCheckReq.State=tblStateTaxDepts.StateAbrv)) INNER JOIN tblUsers AS tblUsers_1 ON tblCheckReq.Approvedby=tblUsers_1.UserName
WHERE (((tblCheckReq.ID)='" & gID & "'));

View 4 Replies View Related

Modules & VBA :: When To Use Global Variable

Apr 8, 2014

I have an application where several different procedures are run repeatedly every xx seconds to get live updates from a server (different procedures depending which form the user currently has open.) Within each procedure, a separate single procedure is called only if a stored boolean setting is set as true. The setting itself is only changed very infrequently, such as on application startup, but needs to be initially set (i.e. it cannot just have a default of False if it is not set.)Because of this I am storing the setting in a single record table and have a function 'UsingWPilot' to return the boolean value. However, given the frequency that the setting needs to be accessed, and the fact that speed is crucial in the running of the app, I am considering adding a global string variable and modifying the function to look at the variable (possible values 'N' and 'Y') and only going to the table if the variable has not been set.

I have heard various things about how you should never if possible use global variables. My question is: is it faster to use a global variable than to open the table record each time?

option 1 :

Code:

Public Function UsingWPilot() As Boolean
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("rbl_Settings_System")

Option 2:

Code:

Public Function UsingWPilot() As Boolean

Dim db As DAO.Database
Dim rs As DAO.Recordset
If Len(g_WPilot) > 0 Then
UsingWPilot = (g_WPilot = "Y")
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl_Settings_System")

[code]....

View 4 Replies View Related

Lose Record Edit Via Form; Input Continues As New Record

Sep 22, 2004

PROCESS AS DESIGNED: The user logs in and is given a form displaying existing records that are coded (by userid) for that user to update. From that list, the user selects a record and continues to a second form (the first form closes) which displays all the fields of the selected record which should/can be edited by the user (plus a few non-editable key fields). There is nothing tricky to how the records are selected for display. A simple query behind the first form selects data records using the userID number. The second form does a simple record select using the active record ID number on the first form. Nothing tricky -- no modules just queries, tables, forms and simple macros to string it all together.

The user can open/close these two forms as often as necessary and the record will continue to show up until a value is entered into a "completion date" field. When that field is no longer blank, the record will no longer be displayed for use.

PROBLEM: About 90% of the time, things work as expected. But 10-15% of the time, somewhere between opening the record in the second form and closing the second form, the edited record totally disappears (as if it were never opened, it isn't even system date stamped) and the input information is inserted instead into a brand new record.

Users can sometimes tell when the edit record is dropped during processing, because key fields displaying previously entered data go blank and the displayed recordID (autonumber) is changed. p>
ERROR PATTERN: NONE! It can happen as the edit record is first opening, in the middle of editing the form, or at the end when closing the form. It will happen on a specific PC 2 times in a row and the third time be fine. It has happened at multiple locations but not for all people and not consistently for the same person/same pc. The same record that failed can be re-selected and work just fine the next time.

I cannot reproduce the error myself. I have tested everything I can think of without causing the error. I can lose changes and avoid a system date stamp if I abort my Access sesssion, but that doesn't create/insert a new record with my new input. It just loses everything.

I have wondered if a momentary break in the network/communications could break the connection to the application to just enough that the form remains on the screen, but selected record is discarded. Input into the empty form would/does insert a new record.

I have asked the IT Operations group to investigate if a network/communication problem could be the culprit, but they haven't gotten far on this. I have never seen this happen before and am totally stumped but am desperate to resolve it before user confidence is damaged.

View 1 Replies View Related

Slow Query Using A Global Variable

Aug 9, 2005

Hello,

I have the following query that I set up as a test, and it runs fine:

SELECT STATUSHISTORIE.*
FROM STATUSHISTORIE LEFT JOIN PROBLEM_DE ON STATUSHISTORIE.PROBLEM_ID = PROBLEM_DE.PROBLEMNR
WHERE (((STATUSHISTORIE.STATUSDATUM)<#1/1/2005#) AND ((PROBLEM_DE.DATENBEREICH)='SPMO') AND (((Left(([PROBLEM_DE].[MODULZUORDNUNG]),InStr([PROBLEM_DE].[MODULZUORDNUNG],"-")-2)))='K29') AND ((PROBLEM_DE.ERLSTAND)<>"WEIF"))
ORDER BY STATUSHISTORIE.PROBLEM_ID,
STATUSHISTORIE.STATUSDATUM;

I then set up two global variables ( a String and a Date) and respective functions to return them – ReturnE( ) and ReturnKW( ). Now my query looks like this, but takes ages to run:

SELECT STATUSHISTORIE.*
FROM STATUSHISTORIE LEFT JOIN PROBLEM_DE ON [STATUSHISTORIE].[PROBLEM_ID]=[ PROBLEM_DE].[PROBLEMNR]
WHERE (((STATUSHISTORIE.STATUSDATUM)<ReturnKW( ) ) AND ((PROBLEM_DE.DATENBEREICH)='SPMO') AND (((Left(([PROBLEM_DE].[MODULZUORDNUNG]),InStr([PROBLEM_DE].[MODULZUORDNUNG],"-")-2)))=ReturnE( ) ) AND ((PROBLEM_DE.ERLSTAND)<>"WEIF"))
ORDER BY [STATUSHISTORIE].[PROBLEM_ID], [STATUSHISTORIE].[STATUSDATUM];

My two public functions that return the global variables look like this:

Public gstrE As String 'global variable: contains E used for query
Public gdatKW As Date

Public Function ReturnE ()
ReturnE = gstrE
End Function

Public Function ReturnKW ()
ReturnKW = gdatKW
End Function


The tables are actually Views set up from an ODBC Data source. Can anyone please tell me why these global variables are causing the traffic jam? :)

Thanks in advance
J

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved