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

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.

Related

Gravity Form->Select Field->Add Option

So Gravity List has a great option in its Drop Down User Interface that let's you add by typing a new option, kinda like an "other" option.
Gravity List Field-Drop Down Option
I want to do this with a normal Drop Down. Thoughts?
You can create a dropdown that is dynamically populated with taxonomy terms, including a term called "other".
When the "other" select option is chosen, conditional logic to a single line text field that will create a new taxonomy term on form submission.
On next use of the form, the dynamic list will have your new single line term too.
Keep using the "other" conditional route to add new options to select.

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

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

How to make one option of a listbox add data to a new field

I have a listbox in a Microsoft Access 2010 form. The listbox has several options and the last one is 'Other'.
When someone selects 'Other' I want the user to be able to type in their data and have it push that data into a different field. Note, I do not want the user to add new options to the listbox.
For instance if the list box was a field called 'Browsers' and my choices were: Internet Explorer, Firefox, Chrome, Other. When the person selects Other, I want them to be able to type in 'Safari' in a field in my database called 'Browsers_Other'.
I cannot seem to figure this out. It looks to be related to similar to 'Cascading Listbox' but I think it is different. I am wondering if I need to have the action open up a sub-form...
You can add a text box bound to the Browsers_Other field. I called my text box txtOther.
Then from the list box's After Update event, enable the text box when the list box selection is "Other". When the list box selection is anything else, disable the text box and set its value to Null.
Private Sub lstBrowser_AfterUpdate()
If Me.lstBrowser.value = "Other" Then
Me.txtOther.Enabled = True
Me.txtOther.SetFocus
Else
Me.cmdSave.SetFocus
Me.txtOther.Enabled = False
Me.txtOther.value = Null
End If
End Sub

Cannot view records in form ms access after assigning record-source

Please help,
I have this table ‘Source_RM’:
Source.........Raw Material.....Waste Date.....Waste Quantity
Store.............Sugar...........13/06/2013.................10
Store.............Salt...............12/06/2013.................13
Production....Sugar............17/06/2013.................10
Vendor..........Sugar............15/06/2013.................10
I have a main form where the client can perform queries passed on controls (text box, combo box ..)
In the main form I need to display a query result passed on combo box value:
The result wanted: the client choose the source from a combo box "cmbSource" so the result will be a table contain the source and total waste i.e.:
Source...Total
Store.......23
What I did is:
Created a form (“Blank Form”) name it: frmResult
In the main form I added Subform, In subform wizard in use an existing form I chose ‘frmResult’
After I choose the source from ‘cmbSource ‘ and click the button’ cmdFilter’
I wrote this code in VBA :
Private Sub cmdFilter_Click()
Me.FormTemp.Form.RecordSource = "SELECT Source_ID, SUM(Quantity) AS Total FROM Source_RM WHERE Source = ' " & Me. cmbSource.Value & " ' GROUP BY Source_ID;"
End Sub
After I click the button, the FormTemp has the RecordSource (I know from the record number at the bottom bar’ 1 of 1’) but the FormTemp still blank .. I need to show the result of query in FormTemp
Note : Date entry in FormTemp is set to NO.
I put the default view of FormTemp to Datasheet.
Please any Ideas
Thank you

How do you edit records from a VBA form that you want to interactively select?

I have a set of ComboBox's in an MS Access 2003 DB that are all bound to fields in a single table. However, the data that they allow you to select doesn't come from that table and instead comes from various other tables. This works fine for the record creation story but now I want to be able to edit the record retroactively. The problem is that I can't figure out how to refill the form elements without writing a bunch of custom code.
My initial inclination is to provide a combo box that limits your choices to record IDs and then do a custom query and use that to set the selected values in all of different form elements. However, I feel like I should be able to do something as simple as DoCmd.GoToRecord , , , ID and the form should repopulate just fine. I'm not opposed to doing the busy work but I'm sure I'm just missing something in my relatively puny knowledge of VBA and Access.
Just to add to the mix, I would offer two approaches, one recommended, the other not.
Approach 1: If you've bound your form to the whole data table (this is the non-recommended approach), you can use the combo box wizard to navigate to the requested record, but I wouldn't recommend it in recent versions of Access:
a. it doesn't allow you to properly name the combo box before it creates code.
b. the code is just WRONG.
Here's the code I just produced in my test database:
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[InventoryID] = " & Str(Nz(Me![Combo2], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
This is wrong in so many ways it's just remarkable. This is what the code should be:
With Me.RecordsetClone
.FindFirst "[ID]=" & Me!cmbMyComboBox
If Not .NoMatch Then
If Me.Dirty Then Me.Dirty = False
Me.Bookmark = .Bookmark
Else
MsgBox "Not Found!"
End If
End With
There is no need to clone the form's recordset when the RecordsetClone already exists.
There is no reason to use an object variable when you can just directly use the pre-existing object.
There needs to be a check for a dirty record before departing the record because if you don't force the save, errors in the save process can lead to lost data.
But the better approach is this:
Approach 2: Use the combo box to change the form's underlying recordsource.
The AfterUpdate event of your combo box would look something like this:
If Not IsNull(Me!cmbMyComboBox) Then
Me.Recordsource = Me.Recordsource & " WHERE [ID]=" & Me!cmbMyComboBox
End If
Now, this only works the first time, as on the second resetting of the Recordsource, you end up with two WHERE clauses, which is not good. There are two approaches:
a. assuming that the form opens without a WHERE clause, store the opening recordsource value in a module-level variable in the form's OnLoad event:
Private Sub Form_Load()
strRecordsource = Left(Me.Recordsource,Len(Me.Recordsource)-1)
End Sub
And at the module level, define strRecordsource accordingly:
Dim strRecordsource As String
Then in the combo box's AfterUpdate event, you have this instead:
Me.Recordsource = strRecordsource & " WHERE [ID]=" & Me!cmbMyComboBox
Now, if your form opens with a WHERE clause already defined, it gets more complicated, but I'll not go into that and leave it as an exercise to the reader what the best approach might be.
I presume that you've already set up the row sources for each combo box. So long as you haven't limited the combo box to that list; it should display what you have stored in that column.
However, if your Combo Box changes its list for each row you can do something like this in the record's OnCurrent event or the field's GotFocus event:
Me.combo_box_name.Requery
After re-reading your question, I think I see what you are trying to achieve. You're on the right track with GotoRecord, although I would probably use OpenForm in this case, because it has a WhereCondition property that allows you to use SQL to specify exactly what record to open. It sounds like you want to implement a "jump to record" type functionality in your form, where the user selects a record ID from a list and the form changes to display the selected record.
One possibility is to switch to the new record each time the user selects an item in the ComboBox. You can handle this in the ComboBox's Click event.
I'll use a simple example: suppose you have a Students table, and a StudentForm for viewing/editing records in the Students table. The StudentForm has a ComboBox cboStudentID that is bound to the Students.ID column via it's RowSource property. When you select a student ID in the ComboBox, the StudentsForm will switch to display the corresponding student record.
In the Click event handler for the ComboBox, you can code this "jump to record" functionality with something like the following:
Private Sub cboStudentID_Click()
Dim recordID As Long
'The ItemData property will return the value of the bound'
'column at the specified index.'
recordID = cboStudentID.ItemData(cboStudentID.ListIndex)
'Jump to the record. This assumes we want to use the same form.'
'You can change the form name if you want to open a different form when'
'the user selects an ID from the ComboBox.'
DoCmd.OpenForm "StudentForm", WhereCondition:="Student.ID=" & recordID
End Sub
As David W. Fenton points out in the comments, you can shorten the following line:
recordID = cboStudentID.ItemData(cboStudentID.ListIndex)
to this:
recordID = Me!cboStudentID
or just:
recordID = cboStudentID
since the default value of the ComboBox in this case will be the value of the bound column at the current ListIndex. In this case, you could just remove recordID altogether and code the Click event as follows:
Private Sub cboStudentID_Click()
DoCmd.OpenForm "StudentForm", WhereCondition:="Student.ID=" & cboStudentID
End Sub