Access 2007:
I'm trying to automatically input the username of the person who created a record in a form called Data Input.
I created a Login Form which works perfectly.
In my Data Input form, in my "User" field, I wrote CurrentUser() in default value of my field. Everytime I create a record it writes Admin, even if I change user in my Login Form.
How can I get my field to take the username that was entered in my Login form?
Thank you
9 14700
Since Access 2007 did away with the built-in user controls, the CurrentUser() function will always return Admin. What you need to do is create your own function to pull the user name from your login form. We would need to know how you are storing this information to be able to help you write the function, however.
I have a table with all the users and their passwords.
The Login form gets the information from this table.
However, I do not store the login information anywhere for now. I know there are many options but I wasn't sure how to proceed from there. You're saying that I should return the information from the login form to a new table (recording the entries of the users) in order for Access to know which user is creating the record in my form?
That is one way. There is also the option of hiding the login form which allows you to reference the value on the form. You can also use temporary variables (tempvars). This last option is what I use to store the login information. There is nothing wrong with the other options though.
If you do choose to do the TempVar method, then during your login process, you would need to create the TempVar. - TempVars.Add "User", your login information
You could then create a function to pull this information. - Public Function LoginInfo()
-
LoginInfo = TempVars("User").Value
-
End Function
Then you can just call this function in your default value property in your form.
Since I'm new to VBA, I understand the code you wrote, just don't know where to input it.
This is my OK button code in my Login Form : - Private Sub Command1_Click()
-
'Check to see if data is entered into Username
-
-
If IsNull(Me.txtUserID) Then
-
MsgBox "Please enter a UserID.", vbOKOnly, "Required Data"
-
Me.txtUserID.SetFocus
-
Exit Sub
-
End If
-
-
'Check to see if data is entered into Password
-
-
If IsNull(Me.txtPassword) Then
-
MsgBox "You must provide a password.", vbOKOnly, "Required Data"
-
Me.txtPassword.SetFocus
-
Exit Sub
-
End If
-
-
'Lookup correct password for username entered in Username
-
-
Me.PasswordLookup.Value = DLookup("[Password]", "User Login", "[UserID] ='" & Me.txtUserID & "'")
-
-
-
'Compare value of Password to PasswordLookup and
-
-
If Me.txtPassword.Value = Me.PasswordLookup.Value Then
-
-
-
'Close logon form
-
-
DoCmd.Close acForm, "Login Form", acSaveYes
-
-
Else
-
MsgBox "Invalid Username/Password. Please try again.", vbOKOnly, "Invalid Entry!"
-
Me.txtPassword.SetFocus
-
Exit Sub
-
End If
-
End Sub
Where do I enter your code?
By the way, you are life saver!
Thank you
Line 27 is where you would enter the first block of code. The second block would need entered in a regular code module (not in a form module or class module).
One last question.. what would be my login information for the first block of code. I get the following error code :
Compile Error :
Wrong number of arguments or invalid property assignment.
Here is the first block of code that I entered : - Private Sub Command1_Click()
-
'Check to see if data is entered into Username
-
-
If IsNull(Me.txtUserID) Then
-
MsgBox "Please enter a UserID.", vbOKOnly, "Required Data"
-
Me.txtUserID.SetFocus
-
Exit Sub
-
End If
-
-
'Check to see if data is entered into Password
-
-
If IsNull(Me.txtPassword) Then
-
MsgBox "You must provide a password.", vbOKOnly, "Required Data"
-
Me.txtPassword.SetFocus
-
Exit Sub
-
End If
-
-
'Lookup correct password for username entered in Username
-
-
Me.PasswordLookup.Value = DLookup("[Password]", "User Login", "[UserID] ='" & Me.txtUserID & "'")
-
-
-
'Compare value of Password to PasswordLookup and
-
-
If Me.txtPassword.Value = Me.PasswordLookup.Value Then
-
TempVars.Add "User", "UserID", "Me.txtUserID"
-
-
-
-
'Close logon form
-
-
DoCmd.Close acForm, "Login Form", acSaveYes
-
-
Else
-
MsgBox "Invalid Username/Password. Please try again.", vbOKOnly, "Invalid Entry!"
-
Me.txtPassword.SetFocus
-
Exit Sub
-
End If
-
End Sub
-
Drop the "UserID" and the double quotes around the control reference so that it is just - Tempvars.Add "User", Me.txtUserID
That names the tempvar "User" and gives it the value that is in Me.txtUserID. You can name it whatever you want. You would just have to change the reference in your other function. If you leave the double quotes around the control reference, then it will pass that text as a literal string so TempVar("User") .Value would equal Me.txtUserID instead of the value that was in the textbox.
Run Time error '32538'
Can only store data and not an object.
I tried the following : - Option Compare Database
-
Public Function LoginInfo()
-
LoginInfo() = TempVars.Add("User").Value
-
End Function
Doesn't give me the runtime error but it tells me that Microsoft Access can't find my function (in my form).
I'm sorry, it's probably really easy for others...
Just copy and paste what I have in the second block of code in post #4. That will fix the function.
In doing some research online, I discovered that you can't call custom functions in the Default Value property of controls. So we will just have to create the functionality of the default value in code. In the form's After Update event, add the following. - If Me.NewRecord Then
-
Me!User = LoginInfo
-
End If
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Nona Me |
last post by:
Is there a program that can make automatically input forms and views using
the table design information in mysql.
for example:
in mysql you have a table: Customer
with the next field: Name, Address, ZipCode, City
the 'automatic form creator' should create a input form with the fields
Name, Address, ZipCode, City, add a submit and reset...
|
by: Therese A. Sorna |
last post by:
Hello all...
I am using Access 2002. I have database set to add users names to the
user level security when they are added to a particular table in a
database, using the Catalog and ActiveConnection commands. I am
getting errors when I try to add a name that is already in the
database. I was wondering if anyone knew of a way to have it...
|
by: jballard |
last post by:
Hello,
I have a database set-up with a form and two subforms in it. I have one
of the subforms (replacement parts) set-up where you can pick part
numbers from a drop down box and also pick a description of the part
from a drop down box. These are two separate fields. I want to be able
to pick the part number and have it put in the...
|
by: Don Sealer |
last post by:
I'd like to have a name show up on a report.
I have a report based on a query. When the report is activated it asks for
a name. I input the name and the query sorts the data and displays it in
the report.
How can I get that name to appear in the report, like a caption? It has to
be able to change each time a different name is entered....
|
by: Tom Nowak |
last post by:
I am writing a webapp in which a user is required to enter a login id and
password on a login form. I have forms authenticaion coded in my web.config.
Once the user is logged in, I want to use the login id in other forms of the
app. I will eventually save a record to a SQL database, and I want the login
id to be automatically entered in a...
| |
by: Funky |
last post by:
Hi,
I have developed an ASP.NET application which has been running in
production for around 3 months without any major glitches. Recently, a
user was attempting to upload a rather large CSV file and ran into a
strange problem.
After roughly 3 minutes of processing, the application reprompted the
user for their user name and password (NT...
|
by: Chuck Anderson |
last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example
and changing those examples to suit my needs. That said ....
..... I have some select fields in a form I created for a database search
that I am unable to figure out how to access. (The search is
implemented in Php/MySQL.)
The user enters search values for: name,...
|
by: lmeeson |
last post by:
hi guys,
I am totally new to coding so please bare with me.
I have a file upload field in a form on a PHP page for users to upload pictures, i also have the following fields in my MySQL database
"image_folder" - this contains a default value of the image folder in my root folder
"image_path" - this automatically combines the image_...
|
by: cloa |
last post by:
I have seen the answer for importing multiple spreadsheets though I haven't tried it. How do I include the spreadsheet filename as the first field for all rows. By the way how does this handle if the workbooks are sometimes formated as one worksheet and sometimes two worksheets. The format is generally very similar.
Function Impo_allExcel()
...
|
by: SeadooRider |
last post by:
I have a database that has in the main table, FirstName, MiddleInitial, and LastName, among other fields.
In my form, the lastname is a combobox that pulls from a POC table. The Firstname and MI are set as
=!(1) etc.
After selecting the last name, the firstname and MI are populated correctly.
However, when I look at the table or any...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |