473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Global variable

68
I have the following logon modules which I used to direct users with varying priviledges to log on to the DB. I want to be able to populate my support log form with the user ID once the user logs on and open that form. I am thinking about putting in a global variable that would capture the UserID and set to the supportlogs form userID field to this value. I have never used global variables before... any help would be good

LOgon module
Expand|Select|Wrap|Line Numbers
  1. Public Sub login()
  2.  
  3. Dim varLog, varPw, varGrp As Variant
  4. varLog = DLookup("[userId]", "users", "[logonid]=Forms!login!loginid")
  5. varPw = DLookup("[userId]", "users", "[password]=Forms!login!password")
  6.  
  7. If varLog = varPw Then
  8.     MsgBox ("Login id confirm")
  9.     varGrp = DLookup("[groupid]", "users", "[password]=Forms!login!password")
  10. Else
  11.     MsgBox ("Invalid LoginID, Try again")
  12.     loginid.SetFocus
  13. End If
  14.  
  15.  
  16. Select Case varGrp
  17. Case 1
  18.   DoCmd.Close acForm, "login"
  19.   DoCmd.OpenForm "mainmenu"
  20. Case 2
  21.   DoCmd.Close acForm, "login"
  22.   DoCmd.OpenForm "mangermenu"
  23. Case 3
  24.   DoCmd.Close acForm, "login"
  25.   DoCmd.OpenForm "dataentrymenu"
  26. End Select
  27.  
  28. End Sub
  29.  
SupportlogForm onCurrent event
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. Dim VarLogon As Variant
  3. VarLogon = userID 'this is the global variable I want to set
  4. With Me.SupportStaff
  5. If Nz(.Value, False) Then
  6.    Me.SupportStaff.Value = VarLogon
  7. End Sub
  8.  
Sep 24 '09 #1

✓ answered by ChipR

Simply create a new code module. The public variables declared here will be persistent outside your form code.

Then after
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
use something like
Expand|Select|Wrap|Line Numbers
  1. Public userID as String
Note that if you stop the running of code or have an unhandled error, the stored values should be wiped from memory.

2 2258
ChipR
1,287 Expert 1GB
Simply create a new code module. The public variables declared here will be persistent outside your form code.

Then after
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
use something like
Expand|Select|Wrap|Line Numbers
  1. Public userID as String
Note that if you stop the running of code or have an unhandled error, the stored values should be wiped from memory.
Sep 24 '09 #2
KingKen
68
thanks much this idea worked just fine
Sep 24 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: David Hitillambeau | last post by:
Hi guys, As I am new to Python, i was wondering how to declare and use global variables. Suppose i have the following structure in the same module (same file): def foo: <instructions>...
4
by: Andrew V. Romero | last post by:
I have been working on a function which makes it easier for me to pull variables from the URL. So far I have: <script language="JavaScript"> var variablesInUrl; var vArray = new Array(); ...
4
by: Dan Elliott | last post by:
Hello, Converting from a working C program to C++, I run into the following error: I have a header: (header.h) namespace shared{ ... struct X{ ...
2
by: Thomas Matthews | last post by:
Hi, I'm getting linking errors when I declare a variable in the global scope, but not inside a function. The declarations are the same (only the names have been changed...). class Book {...
8
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined...
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
10
by: Charles O'Flynn | last post by:
As a complete newcomer (2-3 days) to PHP, although not to programming in general, I have 'dived in' to start a small project to read and parse an XML data stream. I have already worked out most of...
9
by: Ed Jensen | last post by:
I'm having a vexing problem with global variables in Python. Please consider the following Python code: #! /usr/bin/env python def tiny(): bar = for tmp in foo: bar.append(tmp) foo = bar
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.