I have a sub-form that is not displaying data when I change records on the main form. Both forms are based on tables. I've been changing records on the main form via a combo box--works great, displays everything on the main form that it should. The subform is blank--I can enter in new data, but it is not displaying any existing data related to the record displayed on the main form. I need the existing related data to display so that it can be updated (it's a rental inventory, so to mark a checkbox that an item was returned).
Master & child fields are identical and related as follows in a 1:many relationship.
master (tbl Rental Details) = RentalID (PK, autonumber)
child (tbl Rental Inventory) = RentalID (FK, number)
Data entry: No on both.
Filter on Load: No on both.
Access crashed on me twice, and then started giving me some fun errors (return without gosub) on this form so I ran a decompile and compact & repair. The errors are gone, but it started doing this and I'm stumped. Any ideas?
Related
I am trying to build a simple ms Access database.
For the sake of convenience, I will translate into sales, orders and such.
Orders
OrderID - PK (auto number)
Client ID - FK to clientID in the Clients table
Clients
ClientID - PK (auto number)
LastName
FirstName
Company
Address
...
I created a form (main form) that allow the user to specify details for a new order, including the client details.
The same form is used to look the details of older orders, to change their step for instance.
When the clerks types in, I don't know if the client is already registered. After everything has been completed, the clerk saves the new order as a new record in the Orders table.
However, Access complains rightly that the clientID FK has not been set: we set the clients name, first name... but not the ID.
My ultimate goal is that, at the saving of the new record, a request that look up into the Clients table to identify a list of possible candidates that match the client first and last name and open a form (contact form) that nicely displays the data from the first record of the request and allow the clerk to navigate between the records, and eventually select one or select create new record with the data from the main form.
I figured that a good place to do this would be in the save button on my form.
I tried to add something in the event code (macro) with something like (not VBA, a pseudo code I've never seen in the other office applications):
if IsNull([main form]![clientID]) then
bip
launch a request to identify the clients in the clients table with the same first and last name
open a form to look into each selected record and select the correct one or if none is identical generate a new one and return the clientID
end if
executeMenuCommand
command saveRecord
The code I tried above didn't even bipped...
I have placed the bip first, and that didn't bipped either.
I receive a message (explicit) that ms Access could not find a record in the client table with the specified clientID.
So I guess my main question is how do I test if there is a clientID associated with the current record?
The next problem is to come back to the main form with the selected clientID.
From what I have seen in the templates provided by Microsoft, it is avoided by defining a single field for customer in their main form. This field is a list populated from the client table, and if you stray away from the list you get a new form for editing a new client.
This is not the behaviour I am looking into. I need to have the posibility to free text enter every field and chose at the saving moment to create or not a new customer.
I hope I am clear enough, please feel free to ask for more details.
edit: thanks to Gustav's hint, I figured that the event was not to be associated with a button click but on the form itself. It helped me uncover other underlying problems... so I guess my problem is not ripe anymore for soliciting external help.
In VBA, use IsNull, and Me if the form is bound to table Orders:
If IsNull(Me![clientID].Value) Then
I have an access database that holds medical information. It holds quite a bit of information so i have grouped like fields together into individual tables and linked them using a common primary key. I have created a tab style form with subforms on each tab.
Some of these subforms contain fields from only one table, however there are a few subforms where i have included fields from more than one table.
For example, i have a table that holds blood transfusion data and a table that holds patient characteristics. Some Fields from the blood transfusion table and patient characteristics table are in the same subform, but I also have fields from both these tables in other subforms.
When i try to insert data into the sub-forms with fields from multiple tables i get the following errors..
update or cancelupdate without addnew or edit
and
The changes you requested to the table were not successful because
they would create duplicate values in the index, primary key or
relationship. Change the data in the field or fields that contain
duplicate data, remove the index, or redefine the index to permit
duplicate entries and try again.
From researching the problem i gather this is because access is trying to create a new record for both tables, but if a record has already been created with that primary key (from inserting data into a previous subform) it won't edit the existing record.
Does anyone know how to get access to edit the existing record in this instance instead of trying to add a new record? I have basic skills in VBA but this is a bit past my level of experience.
Any suggestions would be greatly appreciated.
I used have a whole long response about split forms instead but I was having a horrible time getting it to work. So here is my new and improved answer for using subforms.
Here is a link with sub form info if you want to brush up for your purposes https://support.office.com/en-us/article/Create-a-form-that-contains-a-subform-a-one-to-many-form-ddf3822f-8aba-49cb-831a-1e74d6f5f06b
Step 1
Make sure your main form is bound to the right table.
For my purposes I used a single combo box on my main form to search with. Make sure all the field parameters on your combo box are correct. This includes making sure the Row Source is correct and that you DO NOT have a control source entered.
Step 2
Don't press enter after making a selection in the combo box. To prevent people from hitting enter I created a dummy button at the bottom that says "Save and Refresh" but all it does it create a message window that pops up with "Save Successful". I find hitting enter creates the first error you keep getting. I'm not sure how to address this in a more sophisticated way yet.
Anything else that comes up I will add later.
I have an Access database (2003 Access) that has a main form linked to a table (tblClientMaster) and a series of subforms. TblClientMaster has a series of unique client names. You can then click on each subform (there are labels with each name that can be clicked on which will open the subforms) and they should filter based on the client you have selected on the main form. I can't filter the subforms based on additional criteria, but I've basically given up on this for now (filter the subform results based on the value of a field on the main form along with an additional parameter, like product name. Every attempt I've made has utterly failed and posting questions on here about it generated no responses, so I've abandoned this for now.)
I am focusing on getting a single subform to work right now (fsubBenCalcs). Each record of the tblBenCalcs has the name of the client which matches the client name listed on tblClientMaster. When you click the BenCalcs subform, it filters the results by client and you can cycle through each record that exists with the same client name. (for instance, Company ABC has 25 calculations that have been completed. Once you select Company ABC, you can click on the BenCalcs subform and it will display the first record and you can cycle through the other 24) However, when I open the main form, it asks me to enter the Parameter value "tblCalculations.Forms!frmMain!ClientName".
First, I don't understand why it is looking for tblCalculations.Forms when tblCalculations is a stand-alone table containing the data for fsubBenCalcs. Second, when I load the main form, it should be completely independent of any value on fsubBenCalcs. Only when I load fsubBenCalcs should it look to the main form for the name of the client.
On the Subform/Subreport (when I go into properties on the main form and find the BenCalcs subform) it has the fields "Link Child Fields" and "Link Master Fields". For these, I put [Forms]![frmMain]![ClientName] for Link Child Fields. For Link Master Fields I just have ClientName.
I have to imagine something is wrong in here, but I haven't been able to come up with the correct way to link these forms. I would appreciate any help or guidance on this. I hope I was clear enough in my description.
Subforms (child) must link to the main form (parent). Subforms are not designed to refer to each other in a partent-child relationship.
You can hack this as follows:
Put a text-box on the main-form (i.e., NOT any of the sub-forms) with the following control source:
=[subForm_1].[Form]![FieldYouWantToLinkBy]
Then, in your "child" sub-form, use the parent-child linking fields to refer to this textbox.
I am working on my first Access 2010 database and have run into a problem editing the recordset returned from a query. This excellent blog entry details several scenarios which can result in uneditable query results. I believe my query results are not editable because my query has a Cartesian Join.
I'm not sure how to avoid this, however. The three tables involved are:
episodes
Individual television episodes
Primary key: "episode_id"
aridates
Individual airdates for a given episode
Primary key: "airdate_id"
Related to "episodes" by "airdate_episode_id"
startdates
Individual download start-dates for a given episode
i.e. when a given episode will be available to download
Primary key: "startdate_id"
Related to "episodes" by "startdate_episode_id"
So, there is no (and I think can be no) direct relationship between airdates and startdates. However, this makes the query:
SELECT episodes.episode_id, episodes.episode_number, episodes.episode_title, airdates.airdate_region_id, airdates.airdate_date
FROM (episodes LEFT JOIN airdates ON episodes.episode_id = airdates.airdate_episode_id) LEFT JOIN startdates ON episodes.episode_id = startdates.startdate_episode_id;
return a recordset which is not editable. I need to be able to see the episode name and number along with the airdate in order to enter a startdate (episodes can not be made available for download before they have aired). So essentially, in this view I only need to be able to edit "startdates.stardate_date".
Thanks in advance for any suggestions... a screenshot of the relationship in question can be seen here.
Create this query:
SELECT
episodes.episode_id,
episodes.episode_number,
episodes.episode_title,
airdates.airdate_region_id,
airdates.airdate_date
FROM
episodes LEFT JOIN airdates
ON episodes.episode_id = airdates.airdate_episode_id;
Use it as the recordsource for a new form. Then create another form which uses a query of only the startdates table as its record source.
Add the second form as a subform to the first form. On the property sheet for the subform control, make the link master field episode_id and the link child field startdate_episode_id.
If you are successful, the subform will display startdates rows where the startdate_episode_id matches the episode_id of the main form's current record. And if you add a new row in the subform, its startdate_episode_id will "inherit" the episode_id from the main form.
I emphasized control earlier because that point can be confusing. The subform control is a member of the main form's controls collection, and the subform control contains the subform. You must find the link master/child field properties on the subform control, not the actual subform itself.
I have a form in MS Access 2010 with two sub forms in it. I've defined one-to-one relationship with the tables behind the forms. Both the sub-forms should be used to create a record in corresponding tables and then update the foreign key in the parent form. But when I fill the sub-form first, an entry is created in the corresponding table but the foreign key doesn't get updated. Shouldn't this happen automatically? Or should I add code for updating parent form's field?
Also when I start filling the main form first and then jump to any of the sub-form, I get the following error message:
"You must enter a value in the 'Activations.dbBoxID' field" (Activations is the main form here and dbBoxID is the foreign key field.)
Another issue is that I don't want sub-forms to update the corresponding tables until an entry in main table is also created (i.e. all required fields in main form are also filled).
I am new to MS Access. Any help would be really appreciated!
The concept you are missing here, and what's not being explained to you is that when you build a master to child relationship in access, you can model these relationships with forms and a sub form, but you base the forms on the actual tables and not queries that are an result of joining those tables together.
In other words, your master form should be based on the main or parent table. DO NOT join in the child table. I'm going to repeat this again: do not join in the child table.
So you can base the master or main form on a query, but when you do so, do not join in the child table in that query. In fact, in most cases there is really no advantage to using and basing a form on a query anyway. Simply create the form, and base it on the table.
The SAME ADVICE applies for the child form. You base the child form on the child table. You DO NOT use a query with a join.
The reason why you're getting error messages is because you have a query for the main form that is based on two tables. With an enforced relationship, when your focus switches from the main form to the child form, a record save of the main form occurs, and thus you're getting the error message.
So your error and problem is due to you basing a form on a query that is a join of two tables when it is not needed in this case.
A form with subforms works better if the data in the parent form are entered first. Then the subforms can be joined on the parent_key to foreign_key in each table without any code.
If you want to let users enter records in subforms first, don't update them until the parent form is completed/saved, you're going to need to do some coding. Not sure why you need/want to do that?
A client form with bills and payments subforms, for example you would enter enough client data to create a record. Then bills and/or payments can then be entered.