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

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.

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.

Bound combobox items refers to different field items

I got a bounded combobox to a group name in vb.net. i can view in the drop down items of the combobox the set of GROUP NAMES. but when i do an insert or update query, i need to make the selected group name refers to the GROUP NUMBER. I don't want to store letters in the database, instead i prefer numbers. how can i do that?!
Here is my code so far :
cmd1.Parameters.AddWithValue("#group", DirectCast(Additemcombobox.SelectedItem,
DataRowView).Item("GroupName"))
Storing the group name in database is currently working well.
My question might not be well explained. Please ask me in case...
any help would be appreciated
You can show one element to the user such as the name, but use a different one for the code to identify the item using DisplayMember and ValueMember
Dim SQL = "SELECT Id, Name FROM GroupCode ORDER BY Name"
...
GrpDT = New DataTable
GrpDT.Load(cmd.ExecuteReader)
cboGroup.DataSource = GrpDT
cboGroup.DisplayMember = "Name"
cboGroup.ValueMember = "Id"
The user will only see the names, while the code can use ValueMember:
Private Sub cboGroup_SelectedValueChanged(...etc
Console.WriteLine(cboGroup.SelectedValue)
End Sub
It prints the Group ID not the name. Depending on the ORDER BY clause in the SQL and the ID, the SelectedIndex may or may not match, so respond to SelectedValueChanged event. If you use SelectedValue instead of SelectedItem you wont have to thrash about with a DataRowView item.
Note that SelectedValue is Object so you will have to cast to integer or whatever for use elsewhere.

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)

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

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.

Resources