MS Access viewing the code of bottom navigations? - ms-access

I want to edit the code of the bottom navigation buttons. I don't want to add custom buttons.
I will add two lines of code in it.
DoCmd.GoToRecord , "", acNext
Me.VendorList.Value = Me.VendorNo

If you want to execute code when the record changes, you can use the forms On Current event:
Private Sub Form_Current()
Me.VendorList.Value = Me.VendorNo
End Sub
This also triggers when the form is loaded, which is wanted in your case I guess.

Related

2 commands on single button

I have a button, and on the button I’m currently using the “DoCmd.OpenForm” command, but would also like the same button to clear the table contents from the previous user on single click. Is this possible?
The button is a Begin button, and once the member clicks begin it will take them to another form to complete, but I want it to clear table contents on the same click.
You can modify the code that the Access Wizard has created to have as many commands as you want. In this case, the code should look like:
Private Sub Command4_Click()
CurrentDb.Execute "DELETE * FROM [Table1];"
DoCmd.OpenForm "Form13"
End Sub
Regards,

Access form does not display records on click event

I have a form (Vendor_Update) that works perfectly. The form is simple - an unbound combo box (cbo_Vendor) is used to filter 4 textboxs for editing. The form is bound to tbl_Vendors. A macro is used on the OnChange event for cbo_Vendor to search for the selected record in tbl_Vendors. I can edit the textboxes and they save to the table, as intended.
I want to open the Vendor_Update form by clicking a button on another form (Form_Start) in my database. I added Cmd_Vendor_Data to the start form with this code in VBA:
Private Sub Cmd_Vendor_Data_Click()
DoCmd.OpenForm "Vendor_Update", acNormal, "", "", acFormAdd
End Sub
The form opens, and I can select a vendor from the combo box, but the text boxes do not populate with the information from tbl_Vendors.
Why does the Vendor_Update form work when I open it exclusively, but not when it is opened by a click event?
One additional note for the Vendor_Update form - this code is in the On Load event:
Private Sub Form_Load()
If Not Me.NewRecord Then RunCommand acCmdRecordsGoToNew
Me.Cbo_Vendor.Requery
End Sub
I am not well-versed in VBA, so any help is much appreciated!
Thank you #HansUp for the assistance! Code corrected and form works as intended.
Private Sub Cmd_Vendor_Data_Click()
DoCmd.OpenForm "Vendor_Update", acNormal, "", "", acFormEdit
End Sub

Change caption of button to field in a table using Access

I am trying to make the caption of a button the content of a field from a table.
Everything I am finding online in forums and MS websites only shows using a macro with the OnClick. I need it to display without every clicking. It also needs to dynamically change every time the field from the table changes.
How can I achieve this? Again, I don't want an event such as OnClick, I want it to simply read as the field from the table reads.
You could simply use the Form's OnCurrent event to set the buttons caption.
On Current:
Private Sub Form_Current()
If Nz(Me.FieldName, "") <> "" Then
Me.btnTest.Caption = Me.FieldName
Else
'Handle blank record here
End If
End Sub
This will make it so ever time the selected record changes the button will update. Also just add the code into the specific field's AfterUpdate event so it changes then as well.
After Update:
Private Sub Textbox1_AfterUpdate()
If Nz(Me.FieldName, "") <> "" Then
Me.btnTest.Caption = Me.FieldName
Else
'Handle blank record here
End If
End Sub

Custom Record Navigation

Hi I have an App with nested sub-forms, the record navigation is confusing and I've started moving the Record Navigation controls to the top of the forms to improve that. I'm stuck on the 'n of n' field, is there a generic property(s)/query that will give me this?
For the first n, use the AbsolutePosition property of the form's RecordsetClone. see MSDN
For the second n, use the RecordCount property.
Update: I prefer Mike's approach using CurrentRecord. I created a form with 2 text boxes: txtCurrentRecord and txtRecordCount. Then this procedure for the form's On Current event causes the text boxes to display the same values as the built-in navigation bar.
Private Sub Form_Current()
Me.txtCurrentRecord = Me.CurrentRecord
If Not Me.NewRecord Then
Me.txtRecordCount = Me.RecordsetClone.RecordCount
Else
Me.txtRecordCount = Me.CurrentRecord
End If
End Sub
Update2: I added a procedure to Form Load to make sure RecordCount is accurate.
Private Sub Form_Load()
Me.RecordsetClone.MoveLast
Me.RecordsetClone.MoveFirst
End Sub

How can I change the view of an MS Access subform at runtime in VBA code?

This seems like it would be a simple affair, and I am sure I have done this before, but it has been a while since I have done any UI programming in Access. What I need to do is put a button on a form to toggle between datasheet and form view for a subform.
I have found a defaultview property, but nothing that looks like it would toggle the view of the form after it is already open.
Essentially I need the property I can fill in the following code..
sfEmployeeBatchEntry.Form.??? = acFormDS
I found it on my own. I was missing it because it used the silly and clunky RunCommand syntax instead of a simple property or method on the control or form classes.
It ain't pretty, but for posterity, here is the answer.
'You have to set focus to the subform control or the change view call will'
'fail (UGH!)'
MyForm.mySubFormControl.SetFocus
'Change to datasheet view...'
DoCmd.RunCommand acCmdSubformDatasheet
'Change to Form View...'
DoCmd.RunCommand acCmdSubformFormView
I tried a number of different solutions I found on different sites. Some seemed unnecessarily complicated. I cleaned out some of the clutter and found this fits my needs the best.
Dim intView As Integer
intView = Me.Form.CurrentView
If intView = 1 Then
DoCmd.RunCommand (acCmdSubformDatasheetView)
Else
DoCmd.RunCommand (acCmdSubformFormView)
End If
Exit Sub
To Toggle the View of a subForm between Continuous and Datasheet, use this code:
Private Sub cmdToggleView_Click()
If Me.frmViewDetailedTransactionsSub.Form.CurrentView = 1 Then
Me.frmViewDetailedTransactionsSub.SetFocus
DoCmd.RunCommand acCmdSubformDatasheetView
Exit Sub
End If
If Me.frmViewDetailedTransactionsSub.Form.CurrentView = 2 Then
Me.frmViewDetailedTransactionsSub.SetFocus
DoCmd.RunCommand acCmdSubformFormView
Exit Sub
End If
End Sub