MS Access - Advancing through record groups - forms

I have a form with a subform. The record source for the subform is as follows:
SELECT [firstID], [secondID], [AAA], [BBB], [CCC], [DDD]
FROM Table1
WHERE firstID = [Forms].[frm1].[txtfirstID];
The subform groups the records together on the basis of txtfirstID but when I advance through the record selector it goes through every record, as expected. I would like to know if there is a way to click through the groups rather than each record within each group. I'm open to any way of doing it. Perhaps filtering through VBA??
Thanks!

First, add a combo box to your form. Set the RecordSource for the combo box to a distinct list of groups, or, if you have a group lookup table, select * from tblGroups. Set the display field to be group name, and the value field to be group id.
Second, after an item is selected from the combo box, modify the RecordSource sql of the form (your query) so that it uses the current value of the combo box. The value of the combobox would be what your where clause should be looking for.

I think you can do two ways to solve this:
1.- If you related main form to subform by a field. In this case TxtFirstID of Main to FirstID of subform. It do all work when change main form and filter automatically on subform
2.- You can do and event OnChange form TxtFirstID on main form.
Sub TxtFirstID_Change()
Me.subfrmName.Form.RecordSource = "Select * from table1 where firstID=" & Me.TxtFirstID 'change the record source for the SubForm
me.subfrmName.Form.Requery 'Force Access to refresh the Record Source
end sub

Related

Take value from field in Form to a new record in other Table

Would really like some guidance on this one. Not as easy as the title might say at first and I'm stuck beyond all and frustrated.
So:
I have a MainForm (With a current ID I would like to stay on!)
I have a Subform (search engine that searches in various linked excel files)
I have 2 tables; one for the Mainform, and one for Items
So on the Mainform, I display the Subform (search).
I do my search and find a specific item in the excel files
I have a command button, that I want to click save the found item in the search field, into my ItemsTable as a new record.
Currently I'm doing this:
Private Sub Command13_Click()
Forms!MainForm.Form.Item1.Value = Me.Searchresult.Value
End Sub
This does actually post my search result into a new field and saves it into the itemsTable.
My problem: I don't need to actually have a field to post to. I just want it to write directly to my table and store it there as a NEW record. (Right now it just overwrites the previous data. Logically because its the same field every time with the same properties).
Can someone PLEASE help me with this one?
Options:
set focus to the subform container then move to New Record row followed by your code, this is not simple, review https://access-programmers.co.uk/forums/showthread.php?t=127337
use SQL INSERT action then requery the subform
CurrentDb.Execute("INSERT INTO Items(Item1) VALUES('" & Me.Searchresult & "'")

Unable to add record. Joinkey of table not in recordset?MS Acess 2007

I have been trying to have a form where I can enter all my patient details along with the medicines prescribed. I have created 5 tables for this.
tblpatients for patient details with Patient ID as primary.
tblvisit for visit details like visitdt,tests,etc, with Visit_ID as primary.
tblmedicines for list of medicines(which I can add dynamically).
tblqnty for specific doses and qnty mentioned during a specific visit.
I have created a form with all patient and visit info and a subform inside the form with medicines and qnty(in tabular form).
Now I am facing 2 issues:
I am unable to set the subform to blank by default on load the mainform as new record. I have tried that even on subform but not working.
While trying to add a record in the subform I receive the error message
"Unable to add record. Joinkey of table tbkqnty not in recordset?"
1) If with 'blank' you mean 'empty': look at point 2)
2) In the recordset of your subform you MUST have the field Visit_ID.
If you don't want to show it in the subform set it to Visible: No
3) Link the two forms (main- and sub-) with Visit_ID (Table tblVisit) as
Link Master Field and Visit_ID (Table tblmedicines) as
Link Child Field in the Main form 'Data' Property Sheet TAB.
4) In the subform, in the before_Update event set
Sub Form_BeforeUpdate(Cancel As Integer)
Visit_ID = Me.Parent!Visit_ID
End Sub
(supposed that Control Names are equal to the Field Names).
This will ensure that all records in the child table tblMedicines are
related to one record in the table tblVisit.
Hope this helps.

MS Access form -> Combox used to filter other combobox results

I have a dropdown combo box in a form for a "Project_ID" called: Combo28 (this is the primary key basically). There are also 5 other "Error_Code" combo boxes called: cboErrCod1, cboErrCod2, cboErrCod3, cboErrCod4, cboErrCod5.
I'm looking to create some sort of "On Change" code that will only display the Error Codes pertaining to the Project_ID selected in the Combo box "Combo28" only.
The error codes are stored in a separate table and each code is associate to a particular project_Id.
Can anyone help?
I'm not sure why you have exactly five error code comboboxes. To do this easily and let access do all the work for you, you could either:
A: Have a parent form containing the dropdown for project_ID. Create a subform (continuous form view). Set the recordsource to your error codes and Link to Master using Project_ID
B: Create a subform with the recordsource "Select ErrorCodes from yourTable WHERE Project_ID = [Forms]![yourForm]![combo28] Where combo28 is your project_ID. In the after update event for your combobox, call .requery and perhaps .refresh on your subform.

MS-Access, form to view one entry from one to many relationship

I have a table with Orders and a subtable with itemId's (one to many relationship)
In the form i have a Combobox to select a specific Order and another Combobox to select a specific itemId.
For this i have made a Query to view all aviable itemId's in the second Combobox.
I dont know how to view the selected itemId-data in the form.
You can use the Where argument of the Openform action to specify the item.
OpenForm FormName, , , "ItemID=" & ComboName
-- http://msdn.microsoft.com/en-us/library/aa141520(v=office.10).aspx
This assumes that the bound column of the combo is a numeric ID that relates to an ID in the form to be opened.

Axapta: Programmatically switch records in a form

In Dynamics AX 2009, how do you programmatically change to a different record in a form?
My form contains a treeview and a group of bound data fields. When clicking on a record in the tree (the data value for each item in the tree is the RecId of the item I'd like to edit in the form) I'd like to change the form to that record.
I've been using sysSetupForm as an example for working with a tree, but I'm having trouble isolating where the call to change records occurs in their code.
Thanks
Some example:
some_table table;
;
table = some_table:find(recid);
table_ds.findRecord(table); // it's a form datasource method