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 14654
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,...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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 ...
|
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...
|
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...
|
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,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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: 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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 ...
|
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...
| |