Access forms and sub-forms - vba

I am building a database on MS 2003. I have one form which calls for a series of options. This form is based on the table "Categories" which is linked to the main table by Customer ID.
Now, both forms appear together on the same screen, what I am trying to do is have the person select one or more of the categories and in pressing a command button then those categories which were selected will show its respective forms. The forms are invisible until selected and until the command button is pressed.
Since they are two different forms (categories in one) and the entry form on another, How do I program the command button to make the entry form visible FROM the other form?
The sub-form is located in a tab. I dont want to show it as a pop-up but to become visible within the tab where it's located

If the form is open but invisible then you can refer to it as a member of the forms collection and make it visible:
forms("myForm").Visible = true
If the form isn't open then get its name from the AllForms collection of the project and then use the OpenForm method:
docmd.OpenForm currentproject.AllForms("myForm").Name, acNormal

Pseudologic: you are basically going to want to set the Visible property with all of your forms to False during the form's Open event. You should place this Visible = False code in a separate subroutine so that the code structure can be called during other events too. (For example you may want to provide a Reset button so that the user can reset the form, or trigger the "set false" code when a new customer id is selected.) Then with every selected category you would set its associated form property visible by setting Visible = True.

Related

Endless form not showing after filter applied previously

I am using unbound endless forms to display data from my database.
The data source is set to queries which provide data to show on the form.
All tinkering with the data itself on the form is blocked (entry, adding, deleting, etc.).
The data on the form can, however, be filtered through Access' standard ways (right clicking on the data and selecting the options or through the navigation buttons down the bottom of the form).
I am using another unbound form as a menu. Buttons on the form let the user open the data display forms. The buttons are connected to the forms through an on- click event that triggers a DoCmd.OpenForm ("frmOutput") line of code to display the form.
Recently I've had users report, that opening the endless data display forms from the menu, filtering data on the form and then closing the form without taking the filter out has resulted in the form not being able to be opened again from the menu (clicking the respective button results in no action whatsoever). The bug seems to even save to the application somehow and moving the (frontend) file to another machine still shows the same error of not showing the form.
It seems that the bug appears more often when people use multiple screens, and use the application on their second screen (as per their Windows settings).
Does anybody know what causes the bug or how it can be prevented?
Any pointer in the right direction is much appreciated since I am at a loss where to even start looking for the culprit!
Hard to tell but it sounds like their filter is being saved when form is closed
If you already have an event that opens the form, try to just clear the filter property after it opens. You can do this from all your command buttons by just changing the form name that gets passed to it
Private Sub OpenUnfilteredForm(strFormName as String)
Dim frm As Form
DoCmd.OpenForm (strFormName)
DoEvents
If CurrentProject.AllForms(strFormName).IsLoaded Then
Set frm = Forms(strFormName)
With frm
.Filter = ""
.FilterOn = False
End With
End If
Set frm = Nothing
End Sub

How to dynamically open a form within a tab?

I have a parent form with a tab control. The tabs show subforms. Data shown in the parent form is general details about residential property, such as address, etc. In the tabs, the subforms show data that is county-specific and exhaustive, like garage square footage and on and on.
There are 6 tabs with a static subform i.e. that tab always shows the same subform. I'd like the 7th tab to dynamically open a subform depending on which county the property exists in. That is, based on the value of a control (Me.Form.County), populate this 7th tab with the corresponding subform for the highly specific details for that county.
(No, it's not desirable to make one subform that could render data for any county; it'd be huge, relatively. One form per county is the requirement.)
It'd be nice if there's a way to act on the event of clicking on the 7th tab to then open the county-specific subform, though I don't see OnClick for a tab. If there's a way that's close to that simple for the user that'd be fine too.
You can use the Subform.SourceObject property to change which form is displayed in a Subform control.
https://learn.microsoft.com/en-us/office/vba/api/access.subform.sourceobject
You can use the Change event of the Tab Control to respond to the user switching tabs and display the correct subform if they are looking at the desired tab.
Private Sub tabCounty_Change()
If tabCounty.Pages(tabCounty.Value).Caption = "County Info" Then
subCountyInfo.SourceObject = "frmCounty" & Me.Form.County
End If
subCountyInfo.Form.Requery
End Sub

VB.NET Module-level variable to store count of child forms

In this exercise, you’ll create an application with a multiple-document interface that consists of a parent form and two child forms.
Open the project and add a parent form
1. Open the CalculateFlooringCosts project in the CalculateFlooringCostsMDI directory. Then, review the code for the Carpeting Costs and Hardwood Costs forms so you understand how they work.
Add a form to the project, and set the IsMdiContainer property of this form to True to identify it as the parent form. Resize the form so it’s large enough to hold several child forms, and use the Application page of the Project Designer to change the startup form to the new form.
Add the File menu to the parent form
Add a MenuStrip control to the parent form. Then, use the Menu Designer to add a File menu to the parent form. This menu should include four menu items that display a Carpeting Costs form, display a Hardwood Costs form, close the active child form, and exit from the application. Give each menu item an appropriate name, include access keys for the menu and menu items, and include a separator bar between the Close and Exit items.
Add an event handler for the Click event of each item in the File menu. The event handlers for the New Carpeting Costs and New Hardwood Costs items should create a new instance of the appropriate form, set the parent form to the current form, and display the form. The event handler for the Close item should close the active child form, if there is one. And the event handler for the Exit item should exit from the application.
Change the Exit buttons on the Carpeting Costs and Hardwood Costs forms to Close buttons, and change the StartPosition property of these forms to WindowsDefaultLocation.
Test the application to be sure that the items in the File menu work as expected.
Add the Window menu to the parent form
Add a Window menu to the right of the File menu. Then, add three items to this menu that will let the user arrange the forms in a cascaded, vertical, or horizontal layout.
Give each item in the Window menu an appropriate name, and then add an event handler for the Click event of each item that arranges the child forms appropriately.
Set the MdiWindowListItem property of the menu strip so the Window menu will display a list of the open child forms.
Test the application to be sure that the items in the Window menu work as expected.
Add a toolbar to the parent form
Add a ToolStrip control to the parent form. Then, add two buttons to this toolbar with the text “Carpeting Costs” and “Hardwood Costs” on them. Be sure to assign appropriate names to these buttons.
Add an event handler for the Click event of each button that uses the Click event handler for the associated menu to display the form.
Test the application to be sure that the toolbar buttons work.
Add a status bar to the parent form
Add a StatusStrip control to the parent form. Then, add a single ToolStripStatusLabel control to the status bar.
Add a module-level variable to the parent form to store the count of child forms, and give this variable an initial value of 0. Add code to increase or decrease the value of this variable each time a new form is opened or closed.
Add a procedure named DisplayFormCount that sets the Text property of the ToolStripStatusLabel control to “Number of child forms currently displayed: ” appended with the current form count. Then, add code to call this procedure when the form is loaded and each time the form count changes.
Test the application to be sure that the form count is displayed properly.
It's steps 15 and 16 I am stuck on.
I have tried this:
Private Sub DisplayFormCount(Sender As Object, e As EventArgs) Handles Me.MdiChildActivate
Dim activeForm As Form = Me.ActiveMdiChild
Me.sbMain.Items(0).Text = "Number of child forms currently displayed: " & Convert.ToString(Me.MdiChildren.Count)
End Sub
And it works for the most part. Upon form loading, it shows 0, then adding a form will make the count increase by 1. The problem is when I go to close the first child window, it doesn't subract. Afterwards all window closes reduces the count by 1 and when all windows are closed, it still says there's a count of 1.

MS Access VBA to set current selection/record to null on a continuous form

I have a form with a subform that is a continuous form. I have a tab control that displays information related to the record selected in the continuous form; the tab control displays as soon as a record is selected/clicked. That all is grand.
However, after the user updates information in the tab control and clicks a button, I want to hide the tab control until a record is actually clicked on the continuous form.
What is currently happening is that the first record in the continuous subform is selected and I'd like for no record to be selected.
Is there a way to set the current record/selection of a continuous form to nothing or null? I've tried setting the bookmark on the continuous form to null in the button click event using Parent.SubApptList.Form.Bookmark = Null and that does not work for me.
Seems like it should be easy, but I can't figure it out.
After the button click event could you set focus to the parent form? Doing this would force the user to click on a record. Maybe I'm not fully understanding exactly what you're trying to do but if all you want is for nothing to have focus after a button event then that's the route I would take. That's assuming you don't having any on focus events for thr main form.

Loading new form within a navigation tab in ms Access 2010

I have created the following navigation structure in a Microsoft access 2010 database:
You can see that there are two tabs, and the data for the tabs is populated with information linked to the ClientID, which is stored in an un-editable textbox at the top of the form. When the Communications Forms tab is selected, a list of communications forms that have been completed for the specific ClientID is shown. And there is a button to create a new form. My question is how do I write the macro so that clicking on the Create New Form button will cause a blank new form to be loaded in the space that is currently occupied by the List of Forms?
Below is what I have so far. It sends the user to a new form instead of embedding the new form underneath the Communication Forms tab in the current form. How can I change the below so that the blank new form is loaded under the Communication Forms tab in the current form, so that all the navigation controls remain visible/usable?
EDIT:
To address HK1's assumptions below, I am adding the following description of the steps I took to create the form in the screenshot above:
1.) I created a blank form in design view.
2.) I added a listbox to list client fullname and id, and a textbox to filter the listbox.
3.) I added the clientid and fullname textboxes to the form, and set them to change based on
what the user selects from the listbox
4.) I dragged a navigation control onto the form next to the listbox
5.) I dragged a form called "ListOfForms" onto a new tab in the navigation control to create the tab
6.) I added the CreateNewForm command button to the ListOfForms form while embedded in the main form
Here is the result of HK1's suggested code:
While I appreciate it, it does not do what I need. You can see that it just adds an additional row to the list in ListOfForms. Instead, I need the code to place a blank MyForm in the place of MainForm where ListOfForms is currently located. Thus, under the CommunicationsForms tab, all the user would see would be a blank MyForm object, which is a different form than ListOfForms.
When I click on the place where ListOfForms is located in Layout View, I see that it is called NavigationSubForm in the Property Sheet. Thus, NavigationSubForm would swap in MyForm in place of ListOfForms when the user clicks on the Create New Form command button. But if the user clicks on CommunicationForms tab again, ListOfForms would again be placed in NavigationSubForm.
I tried the following:
Private Sub cmdCreateNewForm_Click()
Forms!MainForm!NavigationSubform = MyForm
End Sub
But it generates a Runtime Error '438': Object doesn't support this property or method.
Next, I tried:
Private Sub cmdCreateNewForm_Click()
Forms!MainForm.NavigationSubform.SourceObject = MyForm
End Sub
This causes the NavigationSubForm to go blank, so that ListOfForms disappears. This seems like I am on the correct track, but what do I need to do to get it to put a blank MyForm in the NavigationSubForm instead of just an empty space?
The form you have labeled as "List of Forms" appears to be what's called a continuous form, and I'm guessing it's inside a subform control located on a another form. I'm also guessing that your Create New Form button is probably located on the header section of your continuous form. I'm also making the assumption that your continuous form/subform is bound to an editable recordset/recordsource but there's no way I can tell this by looking at the screenshot.
With these assumptions in place, the code for your Create New Form button would probably be something like this:
Private Sub cmdCreateNewForm_Click()
Me.AllowAdditions = True
DoCmd.GoToRecord, , acNewRec
End Sub
If any of my assumptions above are incorrect than it's likely this code won't work as expected.
Be aware that New Records in continuous forms (and datasheet forms) always appear at the bottom of the list. I'm not aware of any easy way of making them appear anywhere else.