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

VBA Code and Queries

2
Hello everyone,

Here's my problem: I have a table called ContactInformation with a field called CreatedBy. I then used the wizard to create a form called ContactInformation. Now, using the VB Editor, the value of CreatedBy gets automatically filled by the CurrentUser, like this:

CreatedBy.Value = CurrentUser

This causes the value of CreatedBy to become 'Admin' or the username of the user logged into the database.

Then, I have a Query called ContactInformation Query. I wanted this Query to only return records created by the CurrentUser. In other words, only display records in which the username matches the value in the CreatedBy field.

As this is dynamic and the username changes depending on who logs into the database, I'm not sure how this could be done. I also can't seem to find a way to enter VB code into a query.

Anyone??
Nov 13 '07 #1
3 1254
Rabbit
12,516 Expert Mod 8TB
Create a public function in a non-form module whose sole purpose is to return the CurrentUser. You can then call that function from SQL.
Nov 13 '07 #2
aseeri
2
Create a public function in a non-form module whose sole purpose is to return the CurrentUser. You can then call that function from SQL.
Thanks for the reply...

OK, so now I have a function that returns the CurrentUser.. But how do I call it in SQL from the Query?

I am using Access 2003 and I created the Query using the wizard. But I can't seem to find where the SQL query actually goes so I can call that function...
Nov 14 '07 #3
Rabbit
12,516 Expert Mod 8TB
I'm not sure what you mean.. you call the function like you call any other function.

Module1
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Function ReturnUser() As String
  5.    ReturnUser = CurrentUser
  6. End Function
  7.  
Query1
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM Table1
  3. WHERE UserName = ReturnUser();
  4.  
Nov 14 '07 #4

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

Similar topics

1
by: Roger Green | last post by:
I have inherited a complex database that has many dozens of queries that derive data from a people table. I now need to be able to run these queries (from within a significant number of forms)...
3
by: NeilAnderson | last post by:
I'm a fairly new user of access & I've never had any training, so I'm wondering if I'm doing the right thing here, or if it matter at all. I'm building a database for room booking purposes and I'm...
41
by: Matt Alanzo | last post by:
Our SOHO 2 person compay sells furniture (not programmers). In '98 we paid $,$$$ for a VBA -Access '97 accounting application, including VBA source code .... an huge investment for us then (and...
1
by: Aaron | last post by:
Hello fellow programmers, I am trying to run an append/update query from code, a command button on a form initiates the queries. the format i am using is; ...
4
by: Wayne | last post by:
I'm trying to understand at what point the use of code tables contributes to the efficient running of a database when weighed up against the added work of implementing them in data entry and...
2
by: Greg Strong | last post by:
Hello All, I've written code in a test database with test data. Everything seems to be working except compact database in VB code per http://www.mvps.org/access/general/gen0041.htm. The reason I...
17
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
10
by: tlyczko | last post by:
Hello, We have Access databases (backends) that will eventually be consolidated into a SQL Server database, to facilitate data reporting, analysis, etc. Some queries in one Access database...
5
by: Cord-Heinrich Pahlmann | last post by:
Hi, I'm wondering when php executes the code. I have a little script which takes around 10 seconds execution time. In those 10 seconds the script does a lot of mysql_queries and changes some...
1
by: ezderek | last post by:
For many years if I wanted to run an action query from code, I've used code something like this --- dim qd as query dim sSQL as string dim db as database set db = currentdb() sSQL = "UPDATE...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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...

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.