473,324 Members | 2,548 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,324 software developers and data experts.

Referrencing a combobox from a report

105 100+
Hey everyone...

I have a report with 4 labels on it at the top. The first label is lblSunday1, the second is lblSunday2, and so forth...

I have a small form in my Database called frmReports. On this form I have cmbMonths, cmbYears, and cmbDates.

If I select June from cmbMonths and 2008 from cmbYears, all of the Sundays for that month and year are populated into cmbDates (column(1), column(2), column(3), and column(4)).

Here's my trouble...I have in my Rport On Open VBA code this...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2.  
  3. lblSunday1.Caption = Forms!frmReports!cmbDates.Column(1)
  4. lblSunday2.Caption = Forms!frmReports!cmbDates.Column(2)
  5. lblSunday3.Caption = Forms!frmReports!cmbDates.Column(3)
  6. lblSunday4.Caption = Forms!frmReports!cmbDates.Column(4)
  7.  
  8. DoCmd.Maximize
  9.  
  10. End Sub 
However, I get an error when I try to open the report filtering to those specific cmbDates values.

Error: DataType Mismatch

What am I doing wrong?

Thanks!
May 13 '08 #1
1 1276
jmarcrum
105 100+
Actually I got it working...

I set up invisible text boxes on my frmReports to hold the Sunday values and then just threw them into the report



Expand|Select|Wrap|Line Numbers
  1. Public Function SetTextBoxDutiesDates()
  2.  
  3. Dim TargetDate As Date
  4.  
  5. TargetDate = CDate(Forms!frmReports!cmbMonths & "/1/" & Forms!frmReports!cmbYears)
  6.  
  7. 'loop through days of month and populate txt1st
  8. For i = 1 To GetTextBoxDutiesMonthDays
  9.     If Weekday(TargetDate) = vbSunday Then _
  10.         Forms!frmReports!txt1st.Value = TargetDate
  11.         TargetDate = DateAdd("d", 1, TargetDate)
  12. Next i
  13.  
  14. 'loop through days of month and populate txt2nd
  15. For i = 1 To GetTextBoxDutiesMonthDays
  16.     If Weekday(TargetDate) = vbSunday Then _
  17.         Forms!frmReports!txt2nd.Value = TargetDate + 0
  18.         TargetDate = DateAdd("d", 1, TargetDate)
  19. Next i
  20.  
  21. 'loop through days of month and populate txt3rd
  22. For i = 1 To GetTextBoxDutiesMonthDays
  23.     If Weekday(TargetDate) = vbSunday Then _
  24.         Forms!frmReports!txt3rd.Value = TargetDate + 0
  25.         TargetDate = DateAdd("d", 1, TargetDate)
  26. Next i
  27.  
  28. 'loop through days of month and populate txt4th
  29. For i = 1 To GetTextBoxDutiesMonthDays
  30.     If Weekday(TargetDate) = vbSunday Then _
  31.         Forms!frmReports!txt4th.Value = TargetDate + 0
  32.         TargetDate = DateAdd("d", 1, TargetDate)
  33. Next i
  34.  
  35. 'loop through days of month and populate txt5th
  36. For i = 1 To GetTextBoxDutiesMonthDays
  37.     If Weekday(TargetDate) = vbSunday Then _
  38.         Forms!frmReports!txt5th.Value = TargetDate + 0
  39.         TargetDate = DateAdd("d", 1, TargetDate)
  40. Next i
  41.  
  42. End Function
  43.  
  44.  
  45.  
  46.  
  47.  
  48. Public Function GetTextBoxDutiesMonthDays()
  49.  
  50. TargetDate = CDate(Forms!frmReports!cmbMonths & "/1/" & Forms!frmReports!cmbYears)
  51.  
  52. 'Exactly 1 week from TargetDate
  53. TargetDate = DateAdd("ww", 1, TargetDate)
  54.  
  55. 'Subtract 1 day
  56. TargetDate = DateAdd("d", -1, TargetDate)
  57.  
  58. GetTextBoxDutiesMonthDays = Day(TargetDate)
  59.  
  60. End Function
  61.  
  62.  
  63.  
  64. Private Sub Report_Open(Cancel As Integer)
  65.  
  66. lblSunday1.Caption = Forms!frmReports!txt1st.Value
  67. lblSunday2.Caption = Forms!frmReports!txt2nd.Value
  68. lblSunday3.Caption = Forms!frmReports!txt3rd.Value
  69. lblSunday4.Caption = Forms!frmReports!txt4th.Value
  70. lblSunday5.Caption = Forms!frmReports!txt5th.Value
  71.  
  72. DoCmd.Maximize
  73.  
  74. End Sub
May 13 '08 #2

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

Similar topics

4
by: Jan | last post by:
I am having problems trying to print a report based on a form. This is a search form only, no data input. There is a query that the form looks at, but then there are numerous comboxes that you...
3
by: Ray Holtz | last post by:
Access 2003 (2000 file format) question: When I run a form, it opens with only a combo box and a button to execute a query based on the criteria tha is selected in the combobox. Then I need...
2
by: Marksmanaz | last post by:
I have a form named with a subform named based on a query with two controls called (text) and (Yes/No Checkbox). When the checkbox value is yes another query filters for Available Counselors...
8
by: Beany | last post by:
Hi, I have a table called tab_main with all the mobile phone users details. I have form with contains a combobox that lists all the users names alphabetically. i would like to select a name...
11
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...
7
by: freeskier | last post by:
hello, i have a form that opens for a report. the user selects criteria from combo boxes, clicks ok, the form is hidden, and that criteria is applied to the recordset of a report that opens. i would...
2
by: JC2710 | last post by:
Hi I have a userform which has criteria entered into it from a combobox. It then runs a report from this form. I would like to display the text entered in combobox on the report. However I dont...
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...
8
jinalpatel
by: jinalpatel | last post by:
Hello!! I have a form which has several tabs. Two of them are Contacts and Reports. On Contacts tab there is a combobox named contactIndex1 which has whole name of a person to contact. On...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.