Microsoft Access - Navigation form is causing my query to not work - sql

I got a form that works amazingly by itself, but the second I attach it to my navigation form. I start to get prompted for user input since this line
[Forms]![frm_addReceiveReportInformation]![cbo_PurchaseOrderID]
no longer works due to the current form becoming subform in the navigation form which was explained in
ACCESS 2010 Navigation Form Query Property
I can't seem to figure a way out of using the !form since I absolutely need to retrieve the ID from a combo box to update another combo box.
I tried multiple ways of using the !forms but I can't seem to wrap my head around how to retrieve my information that I am seeking.
I got the 2 way navigation menu(vertical + horizontal tabs). Anyone got advice or has encounter this problem in the pass, who can direct me down the right path.

To access a field inside a form, which is attached to a navigation tab, you should use the following structure:
[Forms]![YourNavigationTab]![NavigationSubform].[Form]![YourField]
Note: tested in MS Access 2013

In order for queries that contain form references to work, the form must be fully loaded. I think the problem you are experiencing is that the query in the Row Source of the Part Code combo is being evaluated before the form is loaded and therefore you are being asked to input the parameter value.
You can work around this by leaving the Row Source property of the Part Code combo empty until it gets focus for the first time, something like:
Private Sub cboPartCode_GotFocus()
If Len(cboPartCode.RowSource) = 0 Then
cboPartCode.[RowSource] = "Your Query"
cboPartCode.Requery
End If
End Sub

I sometimes just put a button on the navigation form which opens the desired form as a standalone form. It is probably not the neatest solution but it does work.

Related

How do I get to a control in a subform

I want to go to a control in a subform in order to be able to enter data.
I can make a DoCmd.OpenForm but then I get an extra copy of the subform on top of the main form. I would rather go directly to the subform. I have tried a lot of options and the following I thought was the most promising
Me.Subform.SetFocus
Me.Subform.Form.mycotrol.SetFocus
DoCmd.GoToControl "mycontrol"
This piece of code does not stop at the Subform to let me enter data. I have also tried Me!Subform with the same result. I have thought of adding a Stop statement, but then I don't know how to resume execution when data has been entered to the subform.
I think there is something I have not understood. Can someone help me out?
Biørn Veirø
VBA is single threaded. It can't work with Access forms this way. You could do it with a modal popup that returns a value, like an InputBox. Access forms don't return a value this way.
If you really want to have a step by step using Access forms then you need to hook in to form events. For this specific case I think the event you want is TextBox.AfterUpdate
https://learn.microsoft.com/en-us/office/vba/api/access.textbox.afterupdate-event
You can have different events on each control object, allowing you to have code that runs after each input.
First set focus to the subform control, then the control in the form:
Me!YourSubformControlName.SetFocus
Me!YourSubformControlName.Form!YourControl.SetFocus

How to prevent MS Access report in subform scrolling down each time I use subform.Requery

I have a report in a subform called ViewCurvePrices. At the top of the parent form, a button contains the code:
ViewCurvePrices.Requery
It's pretty simple stuff and refreshes the values as I expect. Unfortunately though, the report also scrolls down about half a line after it runs, which seems like buggy behavior.
Have any of you come across this before, and is there a way to prevent this from happening? This doesn't happen when the requeried subform contains a regular form/datasheet - just when its a report.
I'm using MS-Access 2016.
As Suggested by OP:
I think maybe Tab order has something to do with it, however you have sense discovered that TAB STOP was the culprit.

How to change the order of open "tabbed forms" in MS Access via VBA

I am using "tabbed document" forms in MS Access (each main form that is open has a "tab" to allow users to easily move between forms).
Does anyone know of a way to reorder such opened forms via VBA? I have workaround code that closes all the forms and then re-opens them in the order I need, but it is clunky and slow (some of the forms are big so take a while to load, and often users have applied filters/sorts which I then need to individually re-apply, plus resetting the current record etc etc).
As all I need is to change the order of the forms on-screen, so my approach seems like overkill - but I can't seem to find info on how to do this anywhere!
(FYI I am NOT talking about the order of pages within a tab control, to avoid any confusion!)
Please attached screenshot with three tabbed forms open, I'd like to re-arrange them so eg left to right they become: #Home, Booking Detail, Enquiry Detail
Thanks
Ok, I have inadvertently figured this out.
In testing I found that if you hide a tabbed form, when you unhide it, it doesn't show up in the same position, but in fact now shows as the last form (ie the rightmost tab)
Eureka! Now to reorder the forms I simply hide them, and then unhide them in the order required. Combine this with DoCmd.Echo = False and there is, in my testing, virtually zero overhead.
Phew!
If the user is not seeing all the forms at once, you don't need to waste resource/time loading all forms at once. Load only what the user supposed to see. NavigationControl is very good for that.
Method 1
Move from tabbed documents to NavigationControl. Each tab is loaded OnDemand hence your main form start-up would be much more quicker. If the main and tabbed form are related to each other, use tabbed form's OnOpen event to dynamically change the record source.
I.e. Form_Open => me.RecordSource = Select * form T1 where T1.id = ParentForm.Id
Method 2
If you can't move to Navigation control, simulate the same effect as above.
When tab pages are changed/selected => underlying form gets a record source.
I.e.
Private Sub TabCtl2_Change()
If Me.TabCtl2.value = 1 Then
me.subform1.recordsource = source
me.subform1.LinkChildFields = linkingFieldName 'if related
me.subform1.LinkChildFields = LinkMasterFields 'if related
ElseIf Me.TabCtl2.value = 2 Then
'Your other form
end if
End Sub
This can help you to reduce your loading time.
[Cascading result sets]
In case if all of your forms are showing cascading results, you might want to consider remove record-source for all of your subforms and then re-apply at each selection.
The goal is to minimise loading time and show only necessary data the user is supposed to see/want to see. Hope this helps to have some idea.

Transferring data between two forms?

Okay so I've been searching for a solution for a while but can't seem to find any answers tailored to what I need to do. Also this is my first post here so I'm sorry if I'm being to vague with what I need. Basically I'm creating a program that has a few text boxes on one form and I need to display the data in those text boxes into a list box on another form. There's a button at the bottom of the first form that allows me to switch to form 2 and also display the data in the list box. I can switch to form 2 but nothing shows up in the list box. I also have a few radio buttons and check boxes on form 1 that will affect which constant values will need to show up in form 2's list box as well. One other thing is that I can't just use a form load option for getting data in the list box, it has to happen with the button press because I will be switching between forms and from my understanding the form load option only works once when the form is loaded for the first time. Anyway here is part of my code for form 1 that shows the button click:
Dim strCustomer As String
Private Sub btnPlaceOrder_Click(sender As Object, e As EventArgs) Handles btnPlaceOrder.Click
strCustomer = txtCustomer.Text
frmInvoice.ShowDialog()
frmInvoice.lstCustomerOrder.Items.Add(Me.strCustomer)
End Sub
My first form is frmMain and my second form is frmInvoice. Can anyone please help me with what I need to do differently with this code and what exactly I need to have for my code for form 2 to make this work. Again I am somewhat new to this so I'm sorry if any of this seems vague or if I'm not quite posting this is the right way. Also I'm using VB.
The code you provided should work fine but you are modifying the ListBox after you show the invoice Form. Since you are using showDialog(), the code that follows this statement will only be executed once the dialog form is dealt with (for example if you close it). This means that if you click the button a 2nd time, the ListBox should contain one item. If you switch the two lines so it looks like this, it should do what you expect it to:
frmInvoice.lstCustomerOrder.Items.Add(Me.strCustomer)
frmInvoice.ShowDialog()

How to prevent a sub form from disappearing when the record source is empty

I have created a form in Access that dynamically updates the displayed information based on the user's input. There is a sub form that is also updated by changing the record source. However, there are some instances when the record source will be empty. When this occurs the sub form disappears, never to be seen again. I can't even reference the sub form in VB.
I know there is a way to prevent this. I have seen sub forms that display an empty result while still staying visible. However, I can't seem to find the setting that does this.
Any Ideas?
The issue was a null record set in the super form and/or the sub form. I linked the sub form to a table to ensure there would be some record. Then, I linked the fields that I wanted to filter by to the super form. The super form contained the records I wanted to filter by: kind of like a where clause.
Sorry if the terminology is not correct or the solution is obvious. Access and VBA are fairly new to me.