How to autofill a field from a variable in Access 2007 - ms-access

I have a form for entering information, each user must "login" by entering their name when they start up my database. I would like to auto populate each records "User" field with this name they have logged in with.
I already have the whole login setup except I cant for the life of me work out how to insert the UserName string contents into a field when the user hits save.

If you do not wish to use Windows log-in details, the safest and easiest thing is a table. I generally keep a one row table to hold various details and current user name would work well in such a table. It can be deleted from the table in the log-in script and then updated when the user logs in. You can use DLookUp throughout your application to get the user name.

I would recommend saving the login Username to a global variable. Then in your save method, grab that global variable username and insert it into the field. Look up using global variables and you'll see its pretty easy to use.

Related

Send InputBox data, entered by the user, to a simple table within access database

I'm trying to figure out in VBA how I can add a function that the information that the user inputs into an inputbox is sent to a table, say Table_1, in my access database.
I would like each column to represent an inputbox, so if the user enters their name, it'll go directly into the column and table. Is this possible?

How to pass a logged in user's id/name to the db in a hidden field?

I need help. I am pretty new to forms and mysql.
I have a user form with 2 fields that gets sent to db on submit. I need the db to also be popluated with the submitting user's ID or username. Is this best accomplished with a hidden input field?
Thank you for any help.
The hidden field will work, but is risky. Someone can edit the html on their machine and submit the form with someone elses id; effectively hacking the system.
The common approach is to store the user's id in Session when the user logs in. If there is a user id then there must be some code for username password verification. Find that code. There, if password matches, store the user id in Session. How you do that - google it.
Now that you have the user id in session, while inserting data, use the input fields from the form and user id from the session.
yes you can take input type hidden element in the form and when you are going to submit the form you can get that values as same as you get not text values, then insert values to database, i hope you know about insert query in mysql.
thank you

Local Data in MS Access

I want to have a "Login" form where a user would enter in a number that uniquely identifies them. After this number is entered I want all of the other forms to use that number on this local instance of the application. IE the user is "Logged In".
One solution would be to have a column in the list of users mark whether that user is the "Active" user, and have every form look up that field. This stops working when you want to have multiple people using the front end to access the same back end, as there would now be more than one "Active" user. Is there a way to make a global local variable that I can use to keep track of who is currently using this particular instance of the front end?
For reliable multi-user access each user must have their own local copy of the front-end regardless, so you could just save their ID number in a global variable or a local table in the front-end.
You can have a public function in a module that returns the ID (stored in the module) and call it in queries and form modules.
Note that variables are always stored per process in the RAM and are therefore always per-user.

How can I programatically check if a users password is correct?

I have a secured ms-access application (ie I have an alternative workgroup file) where different users are allocated different member groups, and I use these to control access to sensitive parts of the application.
I have now found a scenario where my normal user is working on a form and wants to perform a "protected" function (I am thinking about deleting a record - not actually deleting it, but marking it as deleted functionally in the database). What I would like to do is pop up an "approval" dialog box with a username and password field and have this normal user call the supervisor over to enter their username and password. I know how to check whether a given user belongs to a given member group - so could check the username entered by the user is one in the supervisory group, but I don't know how to check if this supervisory user has entered their password correctly.
I assume that passwords are held in a table somewhere in an encrypted form. Is there a vb function to check that password, or perhaps a function to encrypt text retrieved from a text box on a form to compare against the encyrpted password in the database.
The user must have entered the correct password for their account to gain access to the program in the first instance, therefore you will only need to check their group membership to confirm whether or not they can carry out this function, no need for another password check.

How to look up values from a table in Access

I have an Access database that is used to store basic info in a table such as first and last name. How would I go about adding the functionality to lookup by last name?
Is there a way to type in the last name and then hit like F12 or something like this? Can someone please point me in the right direction or provide me a link?
SELECT tblPatient.LName AS [Last], tblPatient.FName AS [First]
FROM tblPatient
WHERE (((tblPatient.LName)=[Enter Last Name]));
How do I tie this into my form now?
I'd suggest you create a form, with a textbox 'search' at the top, then either a listbox or subform below to display results.
The listbox record source would be:
SELECT tblPatient.LName, tblPatient.FName
FROM tblPatient
WHERE tblPatient.LName LIKE Forms!myForm!search & '*';
You can either add a Search button, which requeries the listbox, or do the requery via the Change event of the search textbox. The later may be slow if you have a large number of records; if that's the case, you could check that at least 3 (?) characters have been entered before calling the requery.
You just need to create a query in which you put =[?] as the "last name" value.
When you open that view, you'll be asked to type in a lookup value for that field.
Not sure if this is what you are trying to archieve, though...
This is probably a bit overkill for what you want to do, but I assume that you want to perform a search by last name. You should be able to glean the information you need from this article:
Build a search criteria form
http://www.everythingaccess.com/tutorials.asp?ID=Build-a-search-criteria-form
You can create queries in Access if the user you're targeting with the searchability has Access themselves.
From the main Access UI (assuming Access 2007), go to the Create tab and then select the "Query Wizard." Here is an article on the subject.
Otherwise you can create a program and connect to the MDB/ACCDB file running the query programmatically.
Seeing you wish to look up a name and populate the form based on the name selected, I suggest you need a combobox. There is even a wizard for doing exactly what you want. To start, you will need a form bound to a table or query, that is a form with a Record Source.
Add a combobox to your form
Select :
Find a record on my form based on the value I select in my combobox
Select the ID (primary key), Last and First name fields.
Access will display an example, suggesting that you hide the Key (id) column. Accept this.
Choose a name and finish.
There are a few other small things that could be done for neatness, but you will end up with a form that find the record you want. In addition, the combo will autocomplete if you type in a few letter.
If this is an mde, which your subsequent post seems to suggest it is, there is little you can do wuth out the original file. However, you could try opening the database while keeping the shift key held down and see if that allows you to edit. If you cannot get the original and the shift does not work, you could try rescuing the data, if it, too, is stored in this file.