in access need to doubleclick on record in subform to show detail on main form - forms

I have a main form with a subform. The subform is continuous and shows all of the records. The main form works great for adding and editing records. I need to be able to double click on a record in the subform and that record be displayed on the main form for editing.

By experience I reccomend you to achieve what you are trying by placing two subforms into the master one. In one you have the list and in the other the details.
In the master form you place a hidden link field that is populated when you doubleclik on the list.
This field, let´s call it [link] is the Link Master Field in the detail subform, and the Link Child Field is the id (primary key) to identify your selection.
This will link your double click (or simple) with showing the details.

I found a solution that works to move to display the record from the subform in the master for editing.
In the DblClick event on the subform I put in the following code:
Let Forms!FrmNotes.CboNotesID = TxtNotesID 'TxtNotesID is the ID on the subform
Call Me.Parent.DisplayRecord
On the main for I created
Public Sub DisplayRecord()
CboNotesID.SetFocus
DoCmd.SearchForRecord , "", acFirst, "[NotesID] = " & "'" & Screen.ActiveControl & "'"
End Sub

Related

How to create "Go To Next" record button in Access Form that references an alternate form

In my Access dB, I have a Form ("frmSearch") with a Subform ("subFrmData") that references a query ("qryDynamicData").
The Main Form has 6 drop downs that filter the data table in the Subform. The combo boxes are cascading so that once you select one, the entries that appear in the remaining combo boxes are only those entries in the query that correlate to the first selection. The goal is to keep making the data in the Subform data table shorter and shorter. Here are the fields in the combo boxes:
Region
Account Executive
Manager
Engineer
Stage
Project Number ("ProjectSLCT")
When the user filters down to where the list of projects they are looking at is small enough, they use the final combo box ("Project Number") to select an entry from the table. Doing this brings up another form ("MPC_ProjectNotes") as a pop-up form where they can keep track of project specifics. The event looks like this:
DoCmd.OpenForm "MPC_ProjectNotes", , , "Project_Number= '" & Me.ProjectSLCT.Value & "'"
I want to create a Next Record button on the "MPC_ProjectNotes" form that would in effect allow them to run through the steps of selecting the next item in the ProjectSLCT dropdown and thereby relaunching the MPC_ProjectNotes form with the next item from the combo box (and from the datasheet in "subFrmData") without having to close the MPC_ProjectNotes form and adjust the combo box.
Any thoughts? I don't really even know what to google to get myself pointed in the right direction on this. It seems "Next Buttons" aren't generally setup to work across forms.
Ok, here is what I would suggest:
In place of launching form MPC_ProjectNotes to ONE reocrd?
Why not launch the form with the SAME criteria and list as your combo box ProjectSLCT.
Now, we would of course land in the first reocrd of ProjectSLCT. but that's probably ok!
Now say if ProjectSLCT was NOT on the first record? Then we would simple have to add one extra step: move the form to the right record.
So, the logic is this:
Launch the 2nd form to the same "list" as the combo box.
Move the 2nd form to the SAME item currently selected in the combo box.
Now, you don't even have to write a next/previous button, but can simple display the built in navigation buttons. Since the form is LIMITED to the same list, then regular navigation in that form will work and work without you having to write any code!
So someplace in your first form, you EVENTUALLY wind up with this:
combobox data source = select * from tblWhoKnows where (CRITERA GOES HERE!!!).
So, now we simple launch the 2nd form with this:
DoCmd.OpenForm "MPC_ProjectNotes", , , (CRITERA GOES HERE!!!)
Now the form is loaded with the SAME list. We just this extra line of code to move/jump the form to the current selected row in the combo.
forms("MPC_ProjectNotes").RecordSet.FindFirst "Project_Number= '" & Me.ProjectSLCT.Value & "'"
So we open the form to the "list", and then jump to the corrent combo box selected. The result is a form that you can navagate teh combo list, but we jump/started out on the same combox selected item from that list in the form.
So the code will look something like this:
DoCmd.OpenForm "MPC_ProjectNotes", , , (CRITERA GOES HERE!!!)
Forms("MPC_ProjectNotes").RecordSet.FindFirst "Project_Number= '" & Me.ProjectSLCT.Value & "'"
You will of course "change" the above "CRITERA" to the SAME criteria you used in your code to fill out the last combo box.

Retain focus on a record while switching between navigation subforms

I'm beginning to develop a UI for various departments in my office to support the viewing and editing of customer records.
I have a navigation form with each tab being a separate table within the database. One is customer specific info like SSN, first/last name, etc. The next would be address, the following is contact info, orders, etc.
The first form is where they select the customer. All following forms will depend upon who they select here. I need to be able to retain the Record ID from the first form as they navigate elsewhere. Currently, the form resets each time it loses focus.
Is there a way to enable this? The following forms will be filtered according to what they select in the first couple.
Store the Record ID in the Form's Tag property.
Then:
If loading a new form, you can pass it to the form's .OpenArgs property.
If loading a subform, you can get it through the .Parent.Tag property.
User selects a record:
Me.Tag = Me![Record ID]
Opening a new form:
'Open form
DoCmd.OpenForm "frmName", acNormal, , , acFormPropertySettings, acWindowNormal, Me.Tag
'Filter Form
Private Sub Form_Load()
With Me
If Not IsNull(.OpenArgs) Then
.Filter = "[Record ID]=" & .OpenArgs
.FilterOn = True
End If
End With
End Sub
Loading a subform:
'Filter Form
Private Sub Form_Load()
With Me
If Not IsNull(.Parent.Tag) Then
.Filter = "[Record ID]=" & .Parent.Tag
.FilterOn = True
End If
End With
End Sub
Lastly, if navigating between forms, store it in each form's Tag property.
Although not implemented with the navigation form, an article and a full demo on syncing subforms is here:
Synchronizing Multiple Subforms in Access

How to have a button change the form within the subform "window" in Ms Access

I need to create my own "navigation" form in Ms Access. Basically, I have a MAIN form that has one field named LotNumSelect
Then, buttons representing each form the user would like to view.
Button1 - Customer
Button2 - Job Data
etc.
Once the customer clicks a button, the procedure would open the corresponding form in the subform window to the record matching the LotNumSelect field.
So far, I have this.
Private Sub ContactInfo_Click()
Main_Customer_Sbfm.SourceObject = "Main_Customer_Sbfm"
Forms!Form1!Main_Customer_Sbfm.Form!Lot_Number.SetFocus
This nicely switches the form within the subform. the problem is how do I get the form within the subform find the record associated with the data in the LotNumSelect Field?
I tried this..
DoCmd.FindRecord LotNumSelect.Value, acEntire, , acSearchAll
but it's giving me a runtime error of "2162"
"A macro set to one of the current field's properties failed because of an error in a FindRecord action argument.

Access Form Go To Record

In Access, I have a main form with a listbox. The listbox is used to navigate to different records on the main form. The main form also has a button with the following code to open a dialog form on which I add a new record.
Private Sub New_Btn_Click()
DoCmd.OpenForm "New Issue", , , , acFormAdd, acDialog
Requery
Me.ID_Box.SetFocus
End Sub
After I close the dialog form, I want the listbox to update and to select the new record that added on the "New Issue" form AND I want the main form to navigate to the new record.
I cannot figure out how to make either of these actions occur. Please help me find the best method for these steps.
Assuming the listbox has a rowsource, you can requery the ListBox to show the new record like this:
ListBox1.Requery
Then to move the 'main' form to the latest record (assuming the ID/PK is an autonumber field, which is how the form recordsource is sorted):
DoCmd.GoToRecord , "MainFormNameHere",acLast
If you don't have an ordered recordset, you can use
Me.Recordset.FindFirst "PrimaryKeyField = " & NewRecordPK
Where NewRecordPK is a variable with the new records primary key stored.
You could call this from the dialog if you like. Just make sure you save the record first using something like Docmd.Save Then,
Forms!frmMainForm.Form.Recordset.FindFirst "PrimaryKeyField = " & Me.PrimaryKeyField

Requery subform (1) after adding a new subform (1) record via pop-up subform (2) - Access 2007

I have a form with two subforms (1 and 2). Subform 1 stores the data continously for account breakdowns. Using a pop-up subform (subform 2), the user enters data to change or update the account breakdown stored on subform 1. On submit, the information is stored in the sub-table linked to subform 1, but the data does not refresh and add the new information in a new record in subform 1 unless I manually click the refresh all button in the home tab.
So far, I have tried the following code on form_afterupdate of subform 2, which does requery subform 1 automatically but creates a run-time error (2450) when the main form is closed:
Private Sub Form_AfterUpdate()
On Error GoTo Err_Form_AfterUpdate
Forms!frmSpendPlan!frmSpendPlanSub.Form.Requery
Exit_Form_AfterUpdate:
Exit Sub
Err_Form_AfterUpdate:
MsgBox Err.Description
Resume Exit_Form_AfterUpdate
End Sub
If anyone has a way to automatically requery subform 1 data once subform 2 is submitted without creating an error please let me know, I appreciate any help you can provide.
Thanks!
I have the same problem as you sometimes! The form doesn't refresh properly.
Method 1
try this line of code instead of the current requery code. It shouldn't give you an error but may still not work due to bugs...
Form_frmSpendPlanSub.Requery
I use this format to reference across forms and it works well usually.
Method 2
1) What you can try is in design view click on the form that is doing the "After_Update"
2) Right-Click on the form and click "BUILD EVENT.." and select "Expression Builder"
In expression builder you can see exactly how the form you are in links to the form you want to get to and what you want to do...
So you would navigate yourself by going to FORMS--> Loaded Forms--> frmSpendPlanSub and then from the list you can double click on " "
This will get you referenced to the form you want to affect.
Then all you have to do is copy the code that it gives you in the box above into your VBA code and then reference what you want to do...
E.g.
Forms![frmMainForm]![frmSecondForm].Form![frmThirdForm].Form.Requery
Anyway hope that helps...