MS Access Subform adding multiple rows - sql

I have a form that I use for memo generation which I just added a new subform to which handles contract info. It is a small table which only has the PurchaseID (linked to the main table) and then the contract fields shown as text boxes/combo boxes.
My Issue: Originally what was happening was when a user didn't click into the sub-form shown, no row would be created in the Contract table. If you look at the picture, when the form loads the "PurchaseID" field is populated because it's an autonum linked to the main table. However even though that field is populated, if a user doesn't physically click into the sub-form, no row gets created. I just want the blank row with the default options to be added to the table.
My attempt to fix it:
What I tried doing to fix this is on the event "On Current", I wrote 1 line of code that just sets the value of the combo box to a value. I think this sets the sub-form as a focus and it does end up creating the record. The problem is, now whenever the form loads, it initially tries to add a blank row with the ID of 0 to the Contract table, essentially making a duplicate blank row every time the form opens. I think the reason is because the "On Current" event is happening before the "PurchaseID" field is linking to the main table, resulting in a PurchaseID of "0" continuing to duplicate when the form is opened.
What I need:
Looking at the picture below. How do I make it so when a user does not click in that subform box when going through everything, a new record is added to the sub-form table with the default values selected (procurement/notrequired/etc.).
Picture of form. Sub-form that has issue is circled.

Related

microsoft access requery updates form after 2 requeries

So I have a form (A) , a form (B) , and a table (X). Both forms are based from queries of table (X). The user may click on form A and it will open form B filtered to what that user clicked on. The vba for this works, and is:
docmd.openform "formB" , , , "mykey = " & me.mykey
Once the user is on form B, they have the ability to update table (X) using a combobox dropdown. The user on form B may select a record and a dropdown next to the record that changes information on table X. Once the information is changed, it is updated in the backend table accordingly.
My problem is that these changes are not reflected in either form. The vba I tried to use to update the forms is
forms!formB.requery
forms!formA.requery
The strange thing is that if I click on form A and reopen form B to change a 2nd record, I can now see the previous update. So the 2nd requery updates properly for the first change. Any ideas?
It is a bug in access, not my code. If a combo box has focus when the requery is ran it will not update forms properly, although the table in the back end will still update. I fixed it by added code to the combo box that changes focus after update, now it works.

Trying to open another form in Access based on a field in the current form

I have a form that's just a list of descriptions (desc.) of other forms. Right now, when you click on a desc., the appropriate form opens; but it's done through a series of if statements in a macro. This isn't going to scale well once more forms are created.
I have a table that has the desc. and the form that is supposed to go to. I want to write a script that uses this table to open the new form based on the desc. clicked, but not using if statements. The end goal is to be able to just add a row to the table for any future forms that are created without making changes to the script or form. Is there a way to do this?
Use a combo box whose row source is a query which selects the form description and name fields from your table.
The combo will have 2 columns. You can set the width of the form name column to zero if you want to present only the form descriptions. If you make the form name column the combo's bound column, you can reference it conveniently in a DoCmd.OpenForm statement. For example, you could have a command button whose click event opens the form which is currently selected in the combo ...
DoCmd.OpenForm Me.YourComboName.Value

Error updating field in ms access 2007

I have a form on which there are two subforms.In the afterUpdate() event of combobox of subform1 I want a combobox of subform to get updated with the same value and vice versa.Subform2 depends upon subform2 for its field called ID.As in if I create a new record on subform1 then the subform2 displays data based on records in subform1.New entries can be made in subform1 and modification in the data on subform2 can be made for the records in subform1.This is because subform1 brings data from the base table and subform2 gets related data from some other related tables also.
Everything runs fine if Ihave to update the comboboxes in the 2 subforms for an existing record.However,if I add a new record in subform1,then it throws error "you cannot assign a value to this object" in the afterupdate event of the combobox of subform1.Now if I navigate to subform2 and come back to subform1 and change the value of combobox, it gets updated and throws no error.
The comboboxes in both the forms have same rowsource.
Please suggest me some methods which I can use to avoid this problem.

How to get min/max values on form that returns multiple records

I've got a form that returns multiple records from a table. Each of these records has a field indicating what the measurement was and the measurement's value. My form's record source pulls the appropriate ID's set of measurements and values, and then I want to write each of these measurements to different text boxes on the form.
The problem is that I'm also keeping track of the date this data was updated, and want to include only the data pulled based on the "date updated" selected at the top of the form.
When I go to pull the measurement value into a text box (with something like max(iif(Measurement="Acidity", [Value],[Null])) I get #Error all down my form. This had been working earlier today, and as I've been developing the form something changed and now it no longer works (everything but the date returned is saying #Error). I've set it to Requery when the form loads and whenever the date selected is changed.
EDIT:
This form is actually a subform of another main form. The main form has a control called MemberID which a user can use to select the Member they want information about. This is based on a query that pulls from a table the information related to that MemberID (one row per MemberID). When the form loads, the query behind the main form needs to be requeried to get the data for the selected MemberID.
Then there is this subform causing the problems. On this subform is a "Data Updated" drop down box, which lists the possible dates that the data was updated. When one chooses a particular "Data updated" in the drop down box, this chooses the latest data for all the data measures up to that date selected. This means the form's record source pulls about 10 records in my case.
Then, on this subform I try to layout these 10 records' values in different text boxes. So, in my acidity case above, I would say iif(Measurement="Acidity", [Value], Null). Because there are 10 rows returned, I will end up with 9 Nulls and 1 value, and to get that value I use the max function, so the text box's control source reads: max(iif(Measurement="Acidity",[Value],Null)).
The strange thing is this code was working this morning, until later this afternoon when I was filling in the remaining text boxes with similar code, and then it stopped working. I had also renamed the boxes from Text71 to more relevant names, but none of these are referenced in the code.

Individual Record Subform

I am fairly new to access and I am wondering about a form.
In my form, I want to have certain field values displayed based upon which row the user selects.
So, pretend a user selects Row B, I want a subform that displays data from only Row B.
Is this possible, and if so how? :)
Thanks!
You don't even need a subform for this.
Your main form is a continuous form and your data rows are displayed in the form's detail area, right?
If yes, you can just put bound textboxes in the form header or footer, and they will display the value of the selected row.
Here are some example screenshots I just made.
It's Access 2000 and it's in German (that's the only Access version that I have here), but you'll get the idea.
Design mode:
("Formularkopf" means "form header", and "Detailbereich" is "Detail" in English Access versions.)
At runtime:
Note that the textbox in the form header, which is bound to Field2, automatically displays the value of Field2 in the currently selected row.