I'm trying to link a field, which I have a drop down box in, to a form. I have a list of about 10 forms to pick from. I'm sure this is simple, but I'm just overlooking the obvious.
Simple example code for the opening from the EventName() event (change EventName based on what event you are using):
Private Sub Combo0_EventName()
If Combo0.Value = "Form1" Then
DoCmd.OpenForm "Form1", , , acFormAdd, , , stLinkCriteria
ElseIf Combo0.Value = "Form2" Then
DoCmd.OpenForm "Form2", , , acFormAdd, , , stLinkCriteria
End If
End Sub
Depending on what you are trying to do will determine the event to use, but running the open form command in that event based on the combo box value will get you where you need to go.
Let me understand this right, you have a form with a combo box. When the user selects an option from the combo box, one of 10 other forms open?
How about, in the On Change Of event of the combobox, open the second form?
To clarify:
You open up Access and are presented with a form that contains a combo box filled with some values. You select one of the values and want to bring up a different form and then fill that form out based on some criteria.
The sub routine Combo0_EventName() will take care of opening a form based on the field you select, just put the code in the Combo0_AfterUpdate() routine. To get to that right click on the combo box in design view and select Properties, then click in the "AfterUpdate" event to get [Event Procedure] to show up then click the ... button to get the VB editor.
If you want to fill out the form you open up automatically the method depends on what you are trying to do. You probably want to have another combo box on the first form or on the other forms you are opening that allows you to select your query parameters. Lets say you are opening a form that displays someone's address. You would want a combo box on that form to select from the names in your table and when you select a name it would update a textbox with the address information. Or you could put your query parameter selection on the main form and tie that data to all of the forms so you can go through the forms with the same entry in the table, useful for something like order entry.
If that sounds like what you are trying to do we can move forward down that path, or if it is not please clarify. Can you describe an example of what you are doing? That would be helpful.
I'm sure we can get you going with this.
Im trying to make local tax forms. We do several different local forms and just want the person perparing the return to be able to put in the basic information in a form, which will then automatically pop up which form they are to use, completely filled in. This way all they have to do is enter the basic info in a standard sheet and the local form automatically gets completed. I have made it so when i person picks the municipality from the drop down box it automatically list the form name it needs to go in. But i want it to be simpler than that for them. NE Suggestions?
That makes sense, each form probably has different tax codes, addresses, etc. on it.
I'll see what I can do over the next couple days and set you up with something to get you going.
Related
MS Access novice here with almost no VBA/SQL experience. I've created a database with tables, queries, forms, and reports that all function well together except a few select things I'm stuck on.
Purpose of changing to the below method: Currently, I have created three main report types, with different filter options for each report. AKA: there is a SEPARATE REPORT displaying each different filter option, even though the report contains the same root information. It'd be great to have one report that allows users to filter/group/sort multiple ways to streamline the reporting process.
I'd like to have a 'Filter' button on my Reports form that opens a pop-up window containing filter options via combo boxes. To clarify - the pop-up form has been created and I can easily add a 'Filter Options' button to the report form that opens the pop-up window.
The pop-up form has combo boxes with Control Sources related to the field names on the main table that the report pulls from, as well as buttons for 'Close', 'Apply Filters', and 'Clear Filters'.
What I need help with: getting the combo boxes to supply options as well as get the 'Apply Filters' button to actually work. The filter options need to pull from fields in one of the main tables, with no text entry allowed.
'Apply Filters' button needs to do the following:
Apply filters per combo box selections. Needs to be OK for Users to leave filters blank if they choose.
Gives User a preview of the report w/ applied filters
What you really want to do is close the report and re-open it using the Filter and Preview options. Look into DoCmd.OpenReport. You will have to convert your filter to an SQL language filter based on what he user selects but everything else is pretty straightforward.
So the way I would work this is build a criteria into the form query with a parameter surrounding your popup form's combo box
then in your form vba I'd write:
Private Sub Filter1_AfterUpdate()
DoCmd.Close acReport, "Rpt2_FWItemsDue_AllSubs"
DoCmd.OpenReport "Rpt2_FWItemsDue_AllSubs", A_PREVIEW
DoCmd.Maximize
End Sub
assuming the name of the control is "Filter1" and the name of your form is "Rpt2_FWItemsDue_AllSubs" and "Filter1" filters the "FW_SubName" in the report.
Quick question to do with Microsoft access. I've only been using it for about a week, so theres a lot i dont know.
I have a form with a sub form in it. In the sub form there is a combo box. When the user selects a value in the sub form combo box, i want the mainform's textbox to show what the user picked from the combo box.
I dont think it should be very hard to do, i just have no idea of what the code should be. Thank you in advance!
You can use the After Update event of the subform combo and refer to the main form as Me.Parent. Your code might look like this:
Me.Parent.txtTextBox = Me.cboCombo
I have a form (FORM-A) that requires the user to select a vehicle.
The user should click on a button on FORM-A that say's select vehicle.
A selection form (FORM-B) should open where the user can select a vehicle.
The selected value should be communicated back to FORM-A.
How would you accomplish this in MS Access 2010?
FORM-B is a continuous form that contains a picture of the vehicle and some other information.
From what I understand from your question, you want formB to open a kind of pop-up. When the pop-up is closed, its result is put somehere in the calling form.
Solution proposal:
a) open FormB using syntax docmd.openform "formB", windowmode:=acDialog.
This will prevent execution of the next lines until formB is closed or hidden.
b) in the OK button of FormB, just hide the form, do not close it.
c) when code resumes in formA, you can now
check if formB is still open. If not, it's been cancelled
read the value in hidden formB (still open), then close formB
Otherwise, you could also have formB to update a control in formA before closing. But I don't like that approach because then formB is not reusable, and it creates an unnecessary dependency between formB and formA.
I am not sure why you would need a separate form for this - just have the first textbox be a listing of all the records of vehicles in the database, where you would select one, and the rest of the vehicle information is auto-populated from the vehicle table, but not copied into your parent table. Of course, I am not sure of your table structure either, so there might be a reason for this method that isn't apparent to me.
The benefits of the method above is that if you add more vehicles, your selection box is automatically updated - and you keep the forms you have to load to a minimum (always a good performance move)
You can reference the forms in this manner forms!formName!controlName.
Once you see how this works you will be able to fool with it to get it working with your existing setup. Let’s use 3 controls a text box on Form-A, an image on Form-B and a text box on Form-B. The text box on Form-A will be named txtVehicle, the image on Form-B will be named imgVehicle and the text box on Form-B will be named txtVehicleName.
You can set the name of a control within properties. When you click on imgVehicle it will put the value from txtVehicleName into txtVehicle.
You will have to do a little coding - it's easy though if you have not done it before. Under properties for the image you will see events. If you click on the "On Click" event you will get a drop down list. One of the choices will be [Event Procedure] - choose that. A little button with 3 dots on it will also show up at the end of the row. Click it and you should be taken to a code window with some code like this in it.
Private Sub imgVehicle_Click()
End Sub
Here is where you put your code. Something like this should work. This is it in its most simplistic form.
Private Sub imgVehicle_Click()
Forms!Form-A!txtVehicle=forms!Form-B!txtVehicleName
End Sub
Now although that will work, there are a few things that we should be doing in this method that we are not. We should reference Form-B directly since we are in it, we should verify that Form-A is in fact open.
Private Sub imgVehicle_Click()
If currentproject.allforms(“Form-A”).isloaded then
Forms!Form-A!txtVehicle=me!txtVehicleName
End if
End Sub
Hope that helps
You can create an instance of formB within formA and control it. Below is the VBA code for formA. When clicking on a button on formA, you create a new instance of formB and give it focus. At the same time, you can set properties for its controls. You can use this approach to set the right picture in your control on form B. Hope this helps.
Example:
Option Compare Database
Dim fB As Form_FormB
Private Sub btnA_Click()
Set fB = New Form_FormB
fB.SetFocus
fB.tbxB.Text = "Some text sent from A to B!"
End Sub
If you want both forms to be visible all the time, I suggest using a subform with the list of all the vehicles or just details for the one that the user selected.
I hope someone can help me out, or at least help figure out a workaround.
I'm using Access 2007's split form feature, and have the code below run on the Form_Open event, as well as after two button_click events. The code works fine when run after the button_click events, but when it runs on the form_open event, it causes problems.
If form is opened and user enters text in the first field, he/she cannot use Tab or mouse to select the next form field. The user is stuck on the first form field until pressing Esc to cancel the data entry. In order to successfully enter data in the first form field when the form is opened, a user must first select another form field, then re-select the first form field then enter text in first form field. After this nonsense, the user CAN select next form field with Tab or mouse. This must be performed once every time the form is launched. The same VBA code on the button_click events works fine.
Noteworthy: When the form is first opened, NONE of the form fields in the datasheet section of the form appear 'Selected'. When a user begins to enter data in the first form field, the 'new record' marker (*) moves to the second row as it should, but the first row does not show the data being input. This behavior is odd.
After performing the clear field, click another field, click back to first field workaround described above, the datasheet shows properly selected fields and Data as it is input.
Any ideas? Is this a bug? Is there an easy workaround, such as performing the field-select workaround via VBA at form open?
Any help is MUCH appreciated.
Code:
DoCmd.ApplyFilter , "([Contractor].[CheckOutStamp] Is Null)"
DoCmd.GoToRecord , "", acNewRec
Link to mdb:
https://docs.google.com/leaf?id=0B-jx09cwIQDsYWM2MzMzMDQtYjUzNi00N2E5LWFjYTktNzFiYWYzMDZiYWU1&hl=en&authkey=CPPmoMEF
Some thoughts:
Try moving it from OnOpen to OnLoad. The events in OnOpen can happen before the data is actually loaded, where as OnLoad happens after that is already done.
Also, you might want to just set the form's Filter property to [Contractor].[CheckOutStamp] Is Null and set the FilterOn to Yes, and set the form to DataEntry, which means it defaults to a new record upon open, and doesn't load any of the older records. Once it's open, you can change the form's edit/add mode to whatever you like.
There is a combo box (dropdown list) with a list of revenue types. If the user types into the box a value that is not part of the list, a msgBox pops up and asks them if they want to add that value to the list.
Here is my problem: In that msg box, I want to give the user a combo box list of revenue groups to choose from (so that the essence of the dialog is "oh, you want to add a new revenue type. Now pick which revenue group it's from).
Is there any way to add a combo box to a msgBox?
No, there is not. The usual solution is to build a small form and use that as a dialog.
DoCmd.OpenForm "TheCustomFormName",acNormal,,,,acDialog
You might want to try out Arvin Meyer's MsgBox replacement form:
http://www.datastrat.com/Download/MsgBox2K.zip
I've never used it, but Arvin's an Access guru of long standing.
For what it's worth, what you describe is a dialog, not a message box, so in that case, I'd design a custom dialog form.
Dmitri Furman also has a MsgBox replacement:
http://iridule.net/cu/files/mboxfunction.zip
...but his sounds like a more straightforward replacement, and likely not helpful for your situation. I include the link just for completeness.