473,394 Members | 1,706 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,394 software developers and data experts.

Using a public variable as a Record Source within a table

101 100+
I am trying to open a form to show all records which relate to the Logged in User only for a given date.

My form record source is linked to the table and I want to set a condition where the Table myID matches the current user Login Id. I have the following SQL Select statement.

Expand|Select|Wrap|Line Numbers
  1. SELECT tblRoomsBooking.BookLocation, tblRoomsBooking.BookStartDate, tblRoomsBooking.BookTime, tblRoomsBooking.BookEndTime, tblRoomsBooking.BookName, tblRoomsBooking.Faculty, tblRoomsBooking.myID
  2. FROM tblRoomsBooking
  3. WHERE (((tblRoomsBooking.BookStartDate)=[frmBookings].[BookStartDate]) AND ((tblRoomsBooking.myID)=[basMyEmpId].[lngMyEmpID]))
  4. ORDER BY tblRoomsBooking.BookLocation, tblRoomsBooking.BookStartDate;
The lngMyEmpID is captured at logon and declared as a public variable and is used elswhere without a problem. However, I am getting a paremeter box appearing when I open the form which wants me to enter the ID. I simply want the form to select records based upon the login ID matched to the myID field within the table.

My form does not appear to recognise the public variable and I dont understand why.
Oct 27 '11 #1

✓ answered by NeoPa

It won't. Your public variable is in a VBA module and the Record Source is essentially SQL. Jet, the SQL Engine, has no knowledge of your modules, and no dot (.) syntax for referencing the object structure.

To use it you could design a Public Function procedure which returns that value and call the function within your SQL.

5 3121
NeoPa
32,556 Expert Mod 16PB
It won't. Your public variable is in a VBA module and the Record Source is essentially SQL. Jet, the SQL Engine, has no knowledge of your modules, and no dot (.) syntax for referencing the object structure.

To use it you could design a Public Function procedure which returns that value and call the function within your SQL.
Oct 27 '11 #2
Cyd44
101 100+
Thanks NeoPa,
Thats clear although I am not sure how to do it though. Will have to do some digging.
Oct 27 '11 #3
NeoPa
32,556 Expert Mod 16PB
It's straightforward enough Cyd :

Module = [basMyEmpId]
Expand|Select|Wrap|Line Numbers
  1. Public lngMyEmpID As Long
  2.  
  3. Public Function GetEmpID() As Long
  4.     GetEmpID = lngMyEmpID
  5. End Sub
That way, your SQL would be something like :
Expand|Select|Wrap|Line Numbers
  1. SELECT   [BookLocation]
  2.        , [BookStartDate]
  3.        , [BookTime]
  4.        , [BookEndTime]
  5.        , [BookName]
  6.        , [Faculty]
  7.        , [myID]
  8. FROM     [tblRoomsBooking]
  9. WHERE    (([BookStartDate] = [Forms]![frmBookings]![BookStartDate])
  10.   AND    ([myID] = GetEmpID()))
  11. ORDER BY [BookLocation]
  12.        , [BookStartDate]
Oct 27 '11 #4
Cyd44
101 100+
Many thanks NeoPa. I will save this as an example because I have found a work around that works fine for what I want to do.

Your example however will be very useful to me for other things.

Thanks again
Oct 27 '11 #5
NeoPa
32,556 Expert Mod 16PB
Cyd44:
I have found a work around that works fine for what I want to do.
That's great. The solution was only posted as it matches the question. It's not an approach I would use myself except in extremis. I expect your solution is more appropriate for your requirements than this - which is essentially a kludge, but works (and, of course, it never hurts to know that it is available).
Oct 27 '11 #6

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

Similar topics

3
by: eddiec | last post by:
hi everyone, I have a report in an adp that uses aggregate functions in its record source and I am trying to figure out how to filter the records displayed in the report: DoCmd.OpenReport...
2
by: Lyn | last post by:
If I have a form where the RecordSource property is set to the name of a table, then on opening the SingleForm form I can cycle through all the records in the table one at a time via Next and...
6
by: James White | last post by:
I wish to open a form using a variable derived from a table. The Application is based on the switchboard principle from Access. However in the absence of do.cmd openForm, I have to use this code....
6
by: ApexData | last post by:
I have 2 tables: Table1 and Table2. Neither one has a primary key because each table will only have 1-record. My form is a SingleForm unbound with tabs (my desire here). Using this form, in...
1
by: Robert | last post by:
I have a form that has a table; tblProjects; as its record source. The form is filtered, however, by two combo boxes in the header. One allows the user to select a client, the other a project for...
4
by: is49460 | last post by:
Any help would be very appreciated!!! I have two tables: Main Data and Archived Data. Each table has the same fields (about 50 or so fields). Main data contains records that are updated every...
1
by: Peter Herath | last post by:
I have created a report using sample codes taken by the forum. one problem is that the report displays the field/column names in the table in columnar format(field names display in rows.) but i want...
5
by: doc1355 | last post by:
Hi, I have a script that I need to use a variable to select the database table that I want to update or to get the results from. But for some reason when I use the variable I get error. If I...
2
by: mhifd009 | last post by:
I just wondered what your thoughts were on the best way to reference the 'record source' within a form or report, i am finding that it is best to use the SQL rather than the actual named query (a...
3
by: deneushasler | last post by:
Hello my name is Juan Jose. My problem is as follows. When I try to insert a record into a table (access) to control DetailsView Visual Web Developer 2005, when I run the page and insert a record...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.