MS Access 2003 - Auto fill form-field based on previous form field. - database

I am currently attempting to design a database that requires a number of users inputting data via forms.
one of these tables is a 'user' table. Amongst the information in the table is
userid (int),
username (text),
first name (text),
last name (text)
In the even that I'm filling out a form and supply the the username in the username field is it possible if the username already exists to pull the first name and last name from the user table and auto-populate those form fields? If so can you point me in the right direction please?
Directly via access functionality or via vba? If not possible in 2003 is this possible in 2007?

Ok now for the auto fill (yes i did find one example), This will fill the username after you filled the userid (Both should be comboboxes in this case called Usernamecombo and useridcombo)
First make the query with a SQL similar to this:
SELECT [User].username FROM User WHERE ((([User].userid) Like '*' & [Forms]![Yourform]![useridcombo] & '*'));
Lets call this query "qry_username".
Then go to designview of the form and to the properties of the useridcombo, in the event/afterupdate property you make a event procedure (VBA) :
Private Sub useridcombo_AfterUpdate()
[Forms]![yourform]![Usernamecombo].Value = DFirst("username", "qry_username")
Forms("yourform").[Usernamecombo].Requery 'this last line is optional
End sub
Other fields can be added to the VBA pretty simply(dont forget the query)
Private Sub useridcombo_AfterUpdate()
[Forms]![yourform]![Usernamecombo].Value = DFirst("username", "qry_username")
[Forms]![yourform]![Firstnamecombo].Value = DFirst("Firstname", "qry_username")
[Forms]![yourform]![Lastnamecombo].Value = DFirst("Lastname", "qry_username")
Forms("yourform").[Usernamecombo].Requery 'this last line is optional
End sub

I have a similar form and i use to make these field as Comboboxes.
Then set the property row source as a query.
Set the criteria Where like this
WHERE ((([Users].Username) Like '*' & [Forms]![YourForm]![Username] & '*'));
This will allow the user to choose the name as fast as possible
But it will not fill it automatically because my users can have the same username as others.

Related

Filling form automatically

I do not know way which I can fill my form automatically. I mean that I made easy database which has just table. I made form too. User can write some information about herself/himself, for example name. If he/she end filling places to fill he/she should click send button and all information (expect ID - it gives admin) are on database. User can edit his/her information by clicking button - when he/she click it, it is possibility to write ID - when ID is ready, user can click button load data which fill all places by information connected with this ID.
I tried make some SQL query but it does not work. I past part of my code in window below, but I tried many combination of vba and sql - it always look very easy.
Private Sub button_wczytaj_Click()
OK_imie_wpr.Text = Select OK_imie from Karta_projektu where
Numer_projekt_wpr = Numer_projekt
Form.Refresh
End Sub
button_wczytaj - button which load my data.
OK_imie_wpr - it is place where user can write his name - for example: Tom
OK_imie - it is place where i hold name on my table.
Numer_projekt_wpr - it is blocked place, user get his/her project ID from admin.
Numer_projekt - it is place where I hold ID on my table.
Karta_projektu - it is name of table.
I expect that when I fill place for ID and click load button I get all data connected with my ID. Something like:
SELECT OK_imie from Karta_projektu where ID = [And here i need id which user just write].
select load Button Goto- Property- goto Event Propert- onlick Event-
'Assume your Textbox where you write your ID is Name as 'TxtID'
Dim Query1 as string
Query1 = "SELECT OK_imie from Karta_projektu where ID = " & Me.TxtID & " "
Me.Form.Recordsource = Query1
Me.Form.Requery
I hope you have created a Bound Form.

how to populate a table of lookups using "Not in list"

Table 1: My general information table
Organization: A lookup/relationship field that defaults to "N/A" but pulls values from...
Table 2: Organization List
No ID field, just the names of the organizations in the order which they were added
My data entry form has a combo box for organization and I would like it to update when I add an organization that hasn't been added before. I know I am supposed to use the "Not in List" event, but I don't know how to update the Organization list using this event. How do I do this?
Make sure the Limit To List property of the combo-box is set to Yes.
Add a On Not In List event to insert the value to your source table when a new value appears:
Private Sub MyComboBox_NotInList(NewData As String, Response As Integer)
With DoCmd
.SetWarnings False
.RunSQL "INSERT INTO [Organization List](Organizations) VALUES ('" & NewData & "')"
Response = acDataErrAdded
.SetWarnings True
End With
End Sub
Edit... nearly forgot... before I answer, what have you tried? :)
Edit 2... the example given is for a string value. Remove the ' from either side of New Data if it's a numeric value (but probably not if it's an organisation name).
Edit 3... The INSERT SQL is just one way of putting data into a table. You may prefer the RecordSet.Add and .Update methods.

MS Access 2013 form [control source] lookup field on another table

I feel like I am missing a fundamentally easy process in Access right now.
I have 2 tables with different information on them. Table1 is client info Table2 is client orders. The primary key linking these two tables is the client_id. I made a form to input data into Form2. The form works and I can easily submit data to Form2 but I would like to add a read-only text box beside the client_id field that will display the customers first and last name (stored on Table1) to show the user that the client_id was typed in correctly. Am I going about this the wrong way or am I just missing something? Thanks for any guidance.
In the AfterUpdate event of the client_id field, use DLookup to lookup the client name, and set the value of an unbound, locked textbox to the name.
You can also fetch two fields into one expression:
Me.txtClientName = DLookup("[FirstName] & ' ' & [LastName]", _
"Clients", "client_id = " & Me.client_id)

Is it possible to unlock MS access database field with if sentence?

For example i have 3 fields in one table. Auto numbering ID, name, surname. And I want to unlock surname field only then when name is Jack. Is it possible in MS ACCESS 2013?
You create the form.
You create two textboxes. Create three textboxes if you also want to show the auto field.
You lock/disable all other textboxes other than surname by default.
On the Change_event of the surname textbox you use the following code:
.
Sub txtSurname_Change()
if (Me.txtsurname = "Jack") then
Me.txtSurname.enable = True
Me.txtSurname.Locked = False
Else
Me.txtSurname.enable = False
Me.txtSurname.Locked = True
End if
End Sub
Here it will continously check if what the user typed is Jack. It would be wise to also add code to disable the textboxes again if it is not Jack anymore.

How to set value in a field by UI?

I use three fields in Sqlserver Datavbase tables, for prevent delete records permanently by user:
IsDelete (bit)
DeletedDate (DateTime)
DeletedUserID (bigint)
I wish to set third field (DeletedUserID) by UI by some thing like this:
this.ExamdbDataSet.AcceptChanges();
DataRowView row = (DataRowView)this.BindingSource.Current;
row.BeginEdit();
row["DeletedUserID"] = User.User.Current.ID;
row.EndEdit();
this.ExamdbDataSet.AcceptChanges();
row.Delete();
and other two fields ,'IsDeleted' field and 'DeletedDate' are set automatically in table's 'After Delete Trigger'.
then commit changes to database with desire command successfuly with this code:
this.TableAdapterManager.UpdateAll(this.ExamdbDataSet);
but problem is , the 'DeletedUserID' is null in database.
and Question is : How to set 'DeletedUserID' field value by true way in UI?
I don't think it is a good way to do that. You have sliced a simple logic to separate parts, each being done in a different part of the application (UI, Trigger, ...). You set value of some field, and then DELETE the whole record! Don't expect anything else that the current situation.
You would better set all fields in UI (i.e. no trigger in this case), and change the query that loads data. For example,
Select * from table1 where IsDeleted=0
You didn't tell us anything about whether your use ASP.Net or WinForms. Give us more info.

Resources