I have created a report for Microsoft access and am trying to add fields to a report only if then have been clicked on our filled out. The only way I can think of doing this is writing a code or an if-then statement in access. I have very little experience with writing code and am not sure where to begin. I'm looking for something like "If a checkbox is selected then add it to the report".
Thank you.
Instead of trying to dynamically add controls to a report you could include all of the fields on the report and then simply hide the controls that correspond to empty fields. For example, if you have a text field named [SpecialRequirements] and your report contains a bound text box named [txtSpecialRequirements] then in the On Format event handler of the report's Detail band you could use
Me.txtSpecialRequirements.Visible = (Not IsNull([SpecialRequirements]))
which is just a shorthand way of saying
If IsNull([SpecialRequirements]) Then
Me.txtSpecialRequirements.Visible = False
Else
Me.txtSpecialRequirements.Visible = True
End If
This should get you started - its a basic if structure:
If Me!myCheckBox = True Then
'Write to the report
Else
'Do something else
End If
Also check out the Microsoft Developer Network here for information on the If...Then..Else statement
This is really old, but I had the same issue above, but found a easy solution.
Go to Design view in your "report"
Make your Yes/No boxes not visible
Go to the Design tab in your tool bar
Click on the Controls and click on the Check box and place them over your Yes/No box
Delete the label it gives with the check box
Save and look at your report
Only the YES will appear as a checked box.
Related
I need to print a label on a report only if a checkbox is checked.
I've tried many different lines of code but I can't get it to work. This is what I have at the moment (on the OnFormat event of the footer of my report):
If chkSignature = True Then
CEOsign.Visible = True
Else
CEOsign.Visible = False
End If
and this is a working example you can play with.
If the checkbox is ticked I want to print the label for the signature. If the checkbox is unticked I want to hide it. Can you help me? Thanks.
I didn't download the file, but I am guessing you are not changing the checkbox during the right event. As I recall, Detail_Format is the right event in which to place this code if you want to change visibility of items in the Detail section. MS Access is sometimes finicky, however, and I recall times when this sort of task did not go smoothly. Good luck!
In my DB i have a table called "PrintList" populated with a random number of records and a report called "ReportList", which is linked to "PrintList", that is used to print all the records of the table above.
EDIT: I would let the user to see a print preview in Access to check the list and then choose if print it or not, so i prefer to avoid using code to print.
Is it possible to handle the "ReportList" print event and delete all "PrintList" records after the report is printed? Right now I use a button to empty the list via SQL, but it will be more useful to empty it after printing it.
Report/section events like On Format or On Print are fired both for Print Preview and for actual printing. So the report doesn't know, and thus can't handle your requirement.
I'd use a form with buttons for Preview and Print, and delete the records when the form is closed (because you can't prevent the user from printing from the preview).
The whole requirement looks a bit strange, TBH.
Open your report in design mode.
If the properties pane on the right isnt visible, press F4 to make it visible.
In the properties pane, click on the Events tab.
Find the OnPrint event and click the little ellipses to the right of it to open a VBA window ready to accept your code for that event.
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.
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'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.