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
Related
What i need today is the following:
I have built a form, and i have several tables where that form can write to, how can i make this selectable upon opening the form? Im thinking that basically, before opening the form, i should choose in another form the table to write to, the thing is, the list of tables to write to is not fixed, i have a form that is used to create tables.
For example, i create table x and table y and table w, which are equal in structure and field names and everything, it just changes the table name itself and the values in the fields. how do i tell the form i have that it must write on table x until closing the form and then after closing, when i am to open again, it asks again which table to write to and writes to it until i close the form. Then i decide to create table u and the next time i open the form, table u must be in the list, how feasible is this and how should i approach it?
I already have a table that communicates with the form for creating a new table, hence, keeping a record of every table created, so, i can get the name of the table i want to write to, my problem now is how to change the origin of control in the form, can this be done from code?
On opening of the form you can loop through the tables collection DAO.TableDefs
and fill a listbox with the tableDeft's names.
When the user selects a table name, you set the form's record source to the table name.
You could possibly look into creating a list with a query something like:
SELECT MSysObjects.Name
FROM MsysObjects
WHERE (Left$([Name],1)<>"~")
AND
(Left$([Name],4) <> "Msys")
AND (MSysObjects.Type)=1
ORDER BY MSysObjects.Name;
MSysObjects can get you a list of objects in the database.
Keep in mind, if you have a backend that supplies the tables via linked table manager, you will need to use this:
SELECT Name
FROM MSysObjects
WHERE Databse <> '';
Using this method you can populate a control using this query as the record source. Then, you can prompt the users direction and handle each table specifically and more explicitly.
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.
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).
When producing a list of available parameter properties, rather than manually typing each persons name in one by one, is there any way of just populating the data from the table/view which holds all the possible names?
I assume its in the circled box however all that does it let me point to a dataset and then field which I have tried selecting StaffName (being the field that is the one I'm using) if I then run the report it falls over.
Add a new dataset to the report, maybe called StaffMembersDS. The SQL for it might look like:
SELECT Id, Name
FROM StaffMember;
Then assign Name to Label and Id to Value.
BTW if this is related to your last question you're going to run into the trouble that when a user picks a staff member name from the drop down list they are picking only one value. So for your case you might want the Value field to be tied to Name as well as the label. That would allow you to use the query in your last question - SSRS Parameters - which collects related Id values.
SSRS's concept of a query is largely tied to a data set that you define in Report Data.
When you choose 'Use a query', you should be choosing a pre-defined query from Report Data. Of course, the good news is that you can define these yourself.
So let's take your example. You want your possible parameter options to be StaffNames.
Create a new dataset in Report Data. It should return all possible staff names for your report.
Something like:-
SELECT DISTINCT
StaffName,
StaffID
FROM
MyReportViewOrTable
Once you have defined this dataset, you should be able to use it as a source of parameter values.
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...