I am new to Access and I am using Access 2013. I have a table called Employees which has the employees First_Name, Last_Name and then a Combo Box that is going to have the Full_Name. I have a query that pulls the First_Name and the Last_Name and Concatenates it to the Full_Name field.
Now when I go to my form and add a new employee and click save the field Full_Name in the employee table does not take the Firs_Name and Last_Name and put it into that field. I am not sure what I am missing. I have to go to the Full_Name field after I put the new employee in and go to the drop down where the Full_Name is there. I would like it to automatically put the Full_Name in there.
There are two possibilities that I see:
A. The table is updated, but the form isn't refreshing.
Access forms often don't refresh data as instantly as you would like, and that could be the problem here.
If you add a record, close the form and re-open the form. Does the combo box show correctly?
Try adding a record and clicking "Save". Then press Shift-F9 on your keyboard. Does that make the combo box show correctly?
If yes, then that's the problem. You need to add a requery or refresh method to the VBA code for your "Save" button. (From what you've written, I'm presuming there is VBA code in there.)
B. The table isn't being updated.
If the tests above didn't work, that suggests a field in the table hasn't been updated. You are doing it manually, when you pick the Full_Name in the combo box. In that case, you need to revise the code for the button.
About First and Last Name:
It is better to not have fields for full name, last name and first name -- that means you are storing the names twice, which will lead to problems in your situation.
The typical arrangement is to store first and last names. You can obtain the full name by concatenating those two, which you can do either in a query or in the form.
Alternatively, you could store the full name in one field. To obtain first and last names, you would separate them using functions -- again, in a query or form. This is less common, because less flexible. But it still avoids the problems that are created by storing the same data twice.
Which one is better? That simply depends on your needs.
Related
I'm having a Projects lists Continuous form where the form's Record Source is based upon a table.
I have a requirement to display a field from another table which is linked back to original table using its primary key. The primary key is a AutoNumber field, but when displaying in the form I've used Input mask something like this "TMG/FEA/"0000.
So I made:
a unbound list box
and made the Row source as the query which displays the relevant information from second table
This query was created using primary key displayed in form (I mean the [Forms]![Form Name].[Field] ) as the where clause.
But the results returns blank. I'm Stuck here. I'm not sure if the query is not working due to the Input Mask or because of something else. Please help me. Thanks in advance
You should add to form field listbox, and set following values:
Data: primary key of your first table
After this, that field will duplicate ID value. Now you should transform RecordSource of this field in order to see contents from second table. So you should set:
SELECT [PrimaryForeignKeyID], [DetailedField] FROM tblSecond;. Actually I don't know the contents of your second table. Whereas PrimaryForeignKeyID is a field that links second table to first, so-called FK.
After this set following properties of list box:
ColumnCount = 2
ColumnWidth = 0;2
AllowEdits = False
Save form and open it for viewing.
In this case, your listbox will show the associated contents of second table on form.
So to my mind it is better for you to do such simple tables and forms, and you'll realize idea.
I have hit a roadblock in my access form and I've searched high and low for an answer. I have a form (Enter Numbers) in which users enter information that obviously is stored in a table (Numbers). I need to have a field (# of models) in the numbers table, however, I don't want to ask the users to input that information. Furthermore, in another table (property info) I have that information already inputted. Now before you tell me that it is redundant...blah blah blah, to store the same information in two tables.....the (# of models) field in the (property info) table may change, whereas by storing that number in the (numbers) table each time users enter info in the form, I'm getting a snapshot that will not change.
I have a textbox that uses a dlookup function to pull the (# of models) from the (property info) table and displays it in the form. I had (and have no clue why it no longer functions properly) a button in the form, that when pushed would run the following code " text66 = models " Then I had a docmd.close so that it would put the dlookup result located in field (models) into (text66) whose control source is the field (# of models) in the (numbers) table. This was functioning flawlessly, and then something happened, and now when I click the button I receive a "you can't assign a value to this object" error.
I don't care by what method I copy the dlookup result into the (numbers) table, but I would certainly appreciate any help in doing so! Thanks.
With Access 2010 and later you could use a Before Change data macro on the [Numbers] table to grab a copy of the value from the other table:
I believe this may work for you:
Use an update query. Add the second field, if you need to. Open the query designer. Drag the source field and destination fields onto the query designer. Open the sql view and make your code look like this:
UPDATE table name
SET field2 = field1;
Now execute the query.
field2 is the field you want data copied to. field1 is where the data resides.
There was a thread here regarding a similar question.
This is the simpliest way (I think) :
CurrentDb.Execute "update TableName SET TargetField=SourceField", dbFailOnError
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 want to work on a form, here i will enter the data into text fields and this will be updated into a table as a new entry. Now out of the fields available iwant few of them to be stored into another table. so its like saving form data into multiple tables. I searched in many places but cudnt find any solution.
The best solution is to use a form and a subform. Table1 is bound to form and Table2 is bound to subform.
Thanks for the solution...i dont want to go for another form though...but i figured out a way..for the 2nd table i introduced a button and on click of the event wrote a vb code such that it will look for ID field of type autonumber(introduced for the sake of searching row) and used dlookup with a criteria expression to find out the row in 2nd table n used a insert statement...this worked...thanks for the response, appreciate it...