473,499 Members | 1,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing Report based on combo-box selection

1 New Member
I Created a report from 3 tables named customer,agent and gaurentor also group by Branch and DT on the customers table.
Customers table has agent's Primary key as a field., like wise gaurentor's too

now i want to print the filtered report based on the two combo-box's selection .

i have tried this code
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3.  Private Sub Command2_Click()
  4.   Dim strBranch As String
  5.    Dim strCity As String
  6.   Dim strFilter As String
  7. ' Check that the report is open
  8.   If SysCmd(acSysCmdGetObjectState, acReport, "Report1") <> acObjStateOpen Then
  9.      MsgBox "You must open the report first."
  10.     Exit Sub
  11.    End If
  12. ' Build criteria string for Office field
  13.     If IsNull(Me.Combo0.Value) Then
  14.         strBranch = "Like '*'"
  15.     Else
  16.        strBranch = "='" & Me.Combo0.Value & "'"
  17.     End If
  18.  ' Build criteria string for DT field
  19.     If IsNull(Me.Combo2.Value) Then
  20.     strCity = "Like '*'"
  21.     Else
  22.        strCity = "='" & Me.Combo2.Value & "'"
  23.     End If
  24.  
  25. ' Combine criteria strings into a WHERE clause for the filter
  26.     strFilter = "[Branch] " & strBranch & " AND [DT] " & strCity
  27. ' Apply the filter and switch it on
  28.     With Reports![Report1]
  29.         .Filter = strFilter
  30.         .FilterOn = True
  31.     End With
  32. End Sub
Oct 26 '19 #1
2 2069
NeoPa
32,557 Recognized Expert Moderator MVP
Avinash:
i have tried this code
Are you going to explain what happened? If it didn't work then did the code crash or did it simply not work as you would have expected?

It's hard to answer a question if you don't include a question.
Oct 27 '19 #2
NeoPa
32,557 Recognized Expert Moderator MVP
Require Variable Declaration is a very basic thing you should never be without when working with VBA code. The linked article explains why to do so does you a great disservice.
Oct 27 '19 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2121
by: ROO | last post by:
Hi Everyone, I have a database table that have 4 field( C1, C2, M1, M2) on my form i have two combo box ComboC and ComboM C1 C2 M1 M2 1 ...
5
2675
by: jonosborne | last post by:
Hi, i have managed to filter a report based on selections made in a list box but am totally confused with a message box that appears everytime i run my report. Let me explain (i apologise for...
11
20140
by: billa856 | last post by:
Hi, I have project in MS Access.In that I have one form in which there is one combobox .I want to know when I select an item from that combobox and click on submit button then it should open a...
1
9091
by: Emily Walshaw | last post by:
I'm sorry, I know this has been asked a million times, but am completely new to access and need idiot proof help. I have a database and I am struggling to get a field to update based on a combobox...
0
1469
by: Moorthi chinna | last post by:
how to reload combobox in datagridview based on combobox selection in datagridview?
7
7849
by: bkyzer | last post by:
For my question here are the following: Form Name: popup; Combo1 is the name of the Combobox I want to pass information to my report on load to filter the report output. Query report is based on:...
1
1358
by: sroseindy | last post by:
PLEASE HELP - I NEED THIS TO COMPLETE A CONTRACT!!! Hi all, I have a report based on a crosstab query. The number of columns is dynamic based on the selection criteria the user chooses. I’ve set up...
10
4130
by: simaonobrega | last post by:
Dear Bytes community, Framework: I have created a form using the "Form Design" tool. On the form property sheet, it was added to the Record Source the table which contained the fields that I...
2
5602
by: ERG1982 | last post by:
Hi all, I need to combine the action of a command button to be dependent on the selection in the Combo Box in order to fill the cell with the selection that the combo box refers to. For...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7229
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.