473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Multiple Combo Boxes to setup a report

I am not very good with VBA but I will try to get all the details in here. I am trying to use 5 combo boxes and 2 text boxes to look up and generate a report based off of those selections. I want it to generate a report as well once I click on the command button. I have the 2 text boxes setup as from and to date boxes that I pulled off of another site. I included attachments to try to clarify this a little bit.

The Date Box jpg is the code that i pulled from another site and I am hoping to incorporate the rest of the code into that button. Please help, I've been trying to figure this out for months.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Submit_Click()
  2.  
  3. On Error GoTo Err_Handler      
  4.     Dim strReport As String
  5.     Dim strDateField As String
  6.     Dim strWhere As String
  7.     Dim lngView As Long
  8.     Const strcJetDate = "\#mm\/dd\/yyyy\#"  
  9.  
  10.     strReport = "Search"            
  11.     strDateField = "[Date]"       
  12.     lngView = acViewReport             
  13.  
  14.     If IsDate(Me.startdate) Then strWhere = "(" & strDateField & " >= " & Format(Me.startdate, strcJetDate) & ")"
  15.     End If
  16.     If IsDate(Me.enddate) Then
  17.         If strWhere <> vbNullString Then
  18.             strWhere = strWhere & " AND "
  19.         End If
  20.         strWhere = strWhere & "(" & strDateField & " < " & Format(Me.enddate + 1, strcJetDate) & ")"
  21.     End If
  22.  
  23.    If CurrentProject.AllReports(strReport).IsLoaded Then
  24.         DoCmd.Close acReport, strReport
  25.     End If
  26.  
  27. Debug.Print strWhere  
  28.  
  29.     DoCmd.OpenReport strReport, lngView, , strWhere
  30.  
  31. Exit_Handler:
  32.     Exit Sub
  33.  
  34. Err_Handler:
  35.     If Err.Number <> 2501 Then
  36.         MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Cannot open report"
  37.     End If
  38.     Resume Exit_Handler
  39.  
  40. End Sub
Attached Images
File Type: jpg Date Box VBA Code.jpg (56.2 KB, 126 views)
File Type: jpg Search Form.jpg (47.8 KB, 72 views)
Jul 4 '18 #1
5 1628
PhilOfWalton
1,430 Expert 1GB
Firstly, welcome to Bytes.

Your query should have been posted under Access, not Visual Basic.

Due to the limitations of the Website, images are not all that good, so code should always be pasted between the "[Code/]" Tags

If the image of the form showed only the form, not the surrounding area, it might be readable.

That said, will ALL the Combo boxes and dates be filled in. In other words, if only the dates are filled in, do you want your report to show ALL the data between those two dates?

Phil
Jul 4 '18 #2
I apologize for the post. Not all of the boxes will be filled in, it will only pull from the filled in boxes and display those records. It is for aircraft records so if the dates are filled in as well as the aircraft number I want it to pull every record for that aircraft between those dates.
Jul 4 '18 #3
PhilOfWalton
1,430 Expert 1GB
OK, that clarifies things a bit.

I realise that you are new to Bytes, but it essential that you answer questions as accurately as you can, and respond to requests.

I asked for your code and a clearer image of your form, but got neither. We can't help without the requested info.

Phil
Jul 4 '18 #4
Hopefully that helps a little bit.
Jul 7 '18 #5
PhilOfWalton
1,430 Expert 1GB
Yes, most helpful.

You're om the right track.

All you need to do is check if each Combo box has a value, and if so, add it to the strWhere.

Again you already have the technique of checking whether the strWhere is NOT Null in which case, you add the " AND ", otherwise it starts of with a "WHERE "

Don't forget, if the ComboBox has a string value in it (and I suspect all do other than Document #), then the string needs to be surrounded with quotes.

Something like
Expand|Select|Wrap|Line Numbers
  1. " AND Aircraft = " & Chr$(34) & CboAircraft & Chr$(34)
  2.  
Depending on which column is used to hold the name of the Aircraft, the code may have to say

Expand|Select|Wrap|Line Numbers
  1. " AND Aircraft = " & Chr$(34) & CboAircraft.Column(1) & Chr$(34)
  2.  
One thing you can do to check how you are progressing, is to create a query, and past the strWhere from your Debug Window into the query's Criteria.

Hope that gets you started.

Phil
Jul 7 '18 #6

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

Similar topics

2
by: Damon Cherne | last post by:
Here is my issue. I have created a form called “Search” that has several unbound combo boxes, one for each of the attribute that match a column in the Table . Each combo box has input from a...
2
by: visionstate | last post by:
Hi there, I am working on a form that uses 3 text boxes and 3 combo boxes. When any data is entered into any of these, I click a command button and this requeries a sub query in the form and...
1
by: Shawn Yates | last post by:
It has been a while since I have done anything on MS Access and I seem to be a bit rusty. I hope someone could help me solve my issue. I have a form that has multiple combo boxes on it. Each box...
1
by: JC21 | last post by:
Hi guys, I was wondering if someone could give me some insight on this. On a form I would like to have 3 combo boxes which can be used as filters. I would like the information to be displayed on a...
12
by: micarl | last post by:
How would i print a report based on criteria selected from several Combo Boxes as well as multiple Multi Select List Boxes, that are located on the same form? I can get one Multi List Box, just...
2
by: genkidave | last post by:
Hi there, I have three combo boxes that I would like to have Disabled (grayed out???) and preselected to a particular selection until a radio button (YES) is clicked, thus enabling the combo...
8
doma23
by: doma23 | last post by:
I have 5 combo boxes which represent certain periods. The row source of these 5 combo boxes is table tblRefDate. What I want to do is to make a procedure that when period is inserted in any of...
1
by: Yasmeen Pannu | last post by:
HI, I am new to MS Access and stuck in a problem from few days. My Question: I have 3 combo box (Submitter, date from and date to) on my form and i want that when i select values from each of...
10
by: jss787 | last post by:
Let me start by saying this is my first database. The problem I am having is I have 7 combo boxes on a form that are dependent on each other and only two of them are diplaying unique values. The rest...
5
by: laht0028 | last post by:
Hello, I'm attempting to create a form where the multiple combo boxes are cleared when I proceed to the next record. I have applied the below code and it works to clear one of the combo boxes but...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.