Challenge: I've created a simple repository in MSACCESS (#1) that displays one or more owners of a corporate server.
The sub-form "asset-owners" is linked to the corp-assets main-form (#2). I've added a pulldown whereby the user can select a name (#3) from the address_book (#4) table and prepopulate the owners sub-form.
Objective: I would like to auto populate the associated "Occupation", "Favorite Food", and "Favorite Movie" fields when the user selects a name from the pulldown (#5).
I am not exactly sure how I should configure the occupation food and movie fields to auto-populate with such data AFTER the user has selected the name. I was thinking an inline query for each field, but I suspect it may be simpler than that.
Note: occupation, food, and movie data comes from the address_book (#4).
Many thanks!
I hope you don't want to repeat data in another table. If you just want to display the related data, options:
create multi-column combobox then expression in textbox references combobox column by index - index begins with 0 =[comboboxname].Column(1)
include lookup table in form RecordSource and bind textboxes to fields - set them Locked Yes and TabStop No
DLookup() expression in textbox.
Related
I have a table with a combination of Text Boxes and Comboboxes all bound to fields in a Users table.
The combo boxes are used to select items such as Location, Access rights and Title which are all listed in seperate tables.
However as the values for Location, Access rights and Title are stored in my users table as the integer Primary keys from the related tables this is what is being displayed on my form.
How do I set the combobox field to display the Loc_Name rather than the Loc_ID but still be bound to the original users table?
The second problem I have is that when I select the dropdown for the combo box I get the List of Locations (for example) which is fine and when I select the valid location it displays the Loc_Name in the combobox field. The problem here is that because the combobox is bound to an integer type field in the Users table the form will not accept the String Loc_Name only an integer value.
Am I going about this the wrong way????
Details of settings:
The Location combobox on my form is bound to the Location field in my users table which stores the foreign key integer value from the locations table.
The ComboBox datasource is set to the Locations Table Binding SOurce
The Combobox Display member is set to Loc_Name
The Combobox Value Member is set to Loc_ID
The Selected value is set to (None)
Sorry. Should have put this here.
Looks like I might have been going about it the wrong way. Instead of referencing the valueID with the combo box I had to create a SELECT that join the two data tables and display the Joined data. On update the combobox had to be set to reference the original ID Field. Seeming like a very roundabout way of doing it. No where near as neat as Access.
I am attempting to set the value of a combo box from a "Splash Screen" type form in Access that will take the user's computer name and load two combo boxes on another form with the Employee ID and Manager ID, which are both bound columns of the combo boxes, which are unbound themselves. I can get the IDs in the combo box, but i want it to still display column 2 (Names) of both combo boxes. Right now it just displays the IDs. Anyone got any ideas how i can get it to react like i actually picked it in the combo box?
So, comboboxes can sometimes be tricky, but once you get it down you should be good to go.
So, when looking at a Combobox's properties,
The Format tab :
ColumnCount: 2 <-- You want the ID and the Name
ColumnWidths: 0";1" <--- You're hiding the ID field, which is the first column
The data tab:
This is where you're going to tell Access what data you're supplying for your combobox.
Usually it's a query or table data source. If it's a query you should be selecting the ID and Name fields, and use that query in the RowSource property in the Data tab.
Row Source: Select ID, Name FROM YourTable
Row Source Type: Table/Query
When you use the Wizard to create the combobox, it's fairly straightforward. When Access asks you to format your data source, you completely shrink the ID column, so it hides it (but it's still there).
The steps would be:
I want the combobox to look up the values in a table or query
Select the Table or Query
Select the Fields (ID and Name seem appropriate for your scenario)
Any sorting you may want
The next screen is where we want to hide our ID column, so shrink it entirely
The next screen is where we tell Access that we want the ID to be in scope (selected) when we select a combobox item
Name it & be proud
I am using Oracle with Oracle Forms builder (Middleware) both 11gR2. I am creating a system for purchasing records. I have the following 2 tables.
(a) product (master) : prodid(PK), prodname ...... etc.
(b) purchase (detail) : prodid(FK), quantity, ...... etc.
My plan: All the product details will be in the product table. purchase table will be used only to input purchase information. This table can't input any new product. If any new name, that info will have to be input into product table first. This way I can reduce duplicate names.
Now I am having difficulties relating to prodname (name of the product) column in the form.
I created forms using the purchase table only. This table does not have the prodname (because I put this field in product table) column. But during data entry, they need to see the product name !
So I created text item (tabular, database - no). Then I created LOV, attached to text item, input the prodid in prodid field in the form. LOV part is fine.
I run the form. click the text item, LOV appears, select a name, click OK. product name, product id, etc. appears in their fields as it should be. LOV is working fine. Now I can only input data but having difficulties updating. I mean if I input a name (LOV) in the text item, press execute query, shows records from the database but names in the text item disappear. Since the name is not here, it's not comfortable to update.
I think LOV is not the good idea here. May be I need to use PL/SQL in a trigger somewhere.
But I could not figure it out. I searched google but no luck. Is there anyone who can give me any idea or some example code/trigger please.
Since the product name is an non-database item, when execute query runs, the field is cleared and since no column is assigned to that field, it doesn't repopulate.
The usual way to populate this field is to have a function which returns the product name based on the id that is pressed and call the funtion in POST-QUERY trigger.
Basically it's a pretty simple task but I was having difficulties due to the lack of my experience. However, what I have done is -
create the text item (name : product_name) in the canvas
set properties for the product_name (database : No, .... etc as needed).
Create a block level POST-QUERY trigger and write the PL/SQL block to populate the field. For example, I wrote the following.
BEGIN
SELECT prodname INTO :purchase.product_name
FROM product WHERE product.prodid = :purchase.prodid ;
END ;
That's it and when perform execute_query in the form, it will bring the product name from another table. - Query problem is solved.
Now create an LOV using product table to bring the product name and product id.
Associate this LOV to the product_name text item. So whenever you need to input information about a purchase, just use the LOV to populate the product name field. And then input the subsequent fields as well.
This way both of my issues (query and data entry) are resolved.
I did this according to the suggestions given by Sathya and a video (6 minutes) from the youtube at https://www.youtube.com/watch?v=0nqldnGt8KA.
Thanks to Sathya and youtube.
I have an excel sheet with information about each employee. I keep getting new updated spreadsheet every month. I have to create a database managing cases related to the employees. I have a database and the bounded form already created for the cases which also contain emp info fields. What I am trying to do is to only type in the emp id in the form and want the form to look up in the spreadsheet(which can be a table in the cases db) and populate other fields in the form and that information can go into the cases db. Can this be done?
Assuming the Employee information is available within the current database, perhaps in a linked (Excel), table there are a number of ways to approach this, one of which is:
Create a form based on the Employees table, showing the fields that you are interested in auto-populating
Delete the RecordSource of the form
Delete the ControlSource for each of the controls on the form. You need to do this otherwise they will all initially display with the error #Name?
Set the Locked or Enabled property of these controls to Yes or No respectively, so that the information they will display will not be editable
Add a, for example, Combo Box to the form; you can accept the third option in the Controls Wizard to help you populate this. You need the EmployeedID as the first column, but can add additional columns
Delete the Embedded Macro that Access creates (or Macro for Access 2003 or earlier) for the AfterUpdate event
Click the build button for this event (...) and create some code.
Here is some code I used with my sample Staff Database:
Private Sub cboStaff_AfterUpdate()
Me.RecordSource = "SELECT StaffID, Title, FirstName, Surname FROM " _
& "tblStaff WHERE StaffID = " & Me.cboStaff
With Me
.txtStaffID.ControlSource = "StaffID"
.txtTitle.ControlSource = "Title"
.txtFirstName.ControlSource = "FirstName"
.txtSurname.ControlSource = "Surname"
End With
End Sub
Whenever the user selects a staff (or employee) member from the combobox this will retrieve the data from the table and populate the various controls on the form. These controls will not be editable as they will be locked or not-enabled. (You can also set the Allow Additions and Allow Deletions properties of the form to No, but Allow Edits needs to remain as Yes, otherwise the combobox won't work.)
This code can be improved. In particular, to only set the RecordSource and ControlSource s once.
Obviously I am not aware of the specifics of your database, and there are other ways to approach this.
Added If, however, the RecordSource for the form is some other table that you are hoping to populate with some details from the Employees table then, instead of changing the RecordSource and ControlSource as indicated, you could use ADO (in the AfterUpdate event of the combobox) to create a RecordSet containing a single row (the chosen employee's details) and set the values (the Text) of controls on the form to the values from this recordset. As I say, there are a number of ways to approach this.
Added In response to:
"The changes you requested to the table were not successful because
they would create duplicate values in the index, primary key or
relationship...."
I don't know your precise set-up but I can tell you why this is happening. The default behaviour in Access is that, for a bound form, if a change is made to any one of the bound fields, then an attempt to navigate away from the record will cause Access to save the record.
Is the form bound when it doesn't need to be? Or have you set the ControlSource of a control to a field when it doesn't need to be? If this is not the case then:
In the BeforeUpdate event of the form you can set the Cancel argument to True to prevent the update (or insert). However, this will prevent ANY new record from being inserted. You can either have a Button that the user needs to click to explicitly save the record, or, in the BeforeUpdate event, test some condition with If to decide whether you will allow the insert (or update) or to stop the record from being saved (by setting Cancel = True).
I have an application in Access 2003 that I am working on. In it, I have an employee table, which is connected to two other tables. The two connected tables are tables that hold a few fixed KeyWords. In my main employee table, I just have the ID from the other table, rather than having the whole word.
I wanted to make a form for entering data into these tables, so I made a query from the three tables that shows the all the regular fields of the employee table except instead of those two ID's, I showed the words themselves.
I then made the form and set the query as the RecordSource. The fields that have keywords are Combo boxes on my form, and their ControlSource is the keyword field from the query (like I mentioned earlier, the value can only be one keyword out of a list). Now, the problem I face is this: When I want to see a single record, it shows the correct value in the ComboBox, but when dropdown the menu, it doesnt show any of the other values.
What is the best way to do this? Am I doing this in the wrong way?
Thank you
I'd approach this slightly differently, set the combo box Row Sources to include both the id and text fields (you can hide the ID column if required by setting it's width to zero). Now add the ID fields to the employee query; you shouldn't need to join the other tables to the Employee table in this query, these fields are foreign keys and the combo boxes should show the text for you automatically. Set the form Record Source to this query, now set the combo box Control Source to the appropriate ID value from the form Record Source.
If you let the wizard build a form for you based on the Employee table you will see this approach in action.
ControlSource is the column name of the table where any user entry will be saved.
RowSource is where you type the name of the saved query or manual query typed directly into that field, which is used to provide a list of available drop down options for the combo box.
RowSourceType should be set to Table/Query, which is based on aforementioned RowSource method.
Now to correct the problem of only displaying what you begin to type (i.e. "Allow AutoCorrect" in Property Sheet > Other) or already have saved for that record without other options appearing after clicking the drop down is the following:
In Design View, click the combobox in question.
Property Sheet > Format > Column Count = set the desired number of columns to display in drop down.
Property Sheet > Format > Column Widths = set the desired width of column in the drop down.
Property Sheet > Format > List Width = set the desired width of the drop down itself.
Property Sheet > Data > Bound Column = set to the column of query table (i.e. 1 for ID and 2 for list options, if you only have two entries)
Note: If your desired drop down options are column two and not column one (makes things easier btw) then do the following change from above:
Property Sheet > Format > Column Count = set the desired number of columns to two.
Property Sheet > Format > Column Widths = add two entries 0",1" which means the ID field is not visible (0") and the options field is one-inch.
The easiest way to sort this out in the beginning is to view the column header names to know what you are looking at in the meantime by doing the following:
Property Sheet > Format > Column Heads = set to yes. At least you will know what is showing and whether or not you are on the right track.
I had this same issue in access 2016 and the issue was with my datatype. The combo box didnt accept 'Longtext' so i just changed datatype to 'shorttext' instead and all the values appeared.
You have set the query as the recordsource for the form. A form only shows (and ties to) ONE record at a time.
Since you want the combo box to show all the values, you should set the RecordSource of the ComboBox to your query.