Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 1st, 2006, 03:27 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default Selecting rows for Report

Hello,

I have a table in which the rows each contain the date that they were added.
I am wanting to let a user select a start date and an end date.
Then append the rows that have the dates between the two selections to a report.
Do I need to make a form to do this or can it be done on the report itself?

Thanks
-Dave

 
Old June 1st, 2006, 03:36 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Ideally what you want to do is to set the report to use that table as the recordsource. Then use text boxes on a form for your user to enter the dates. Then when they submit the dates, you validate them and then build a string, something like "myDateField > #1/1/2006
# and myDateField <= #5/31/2006#"

Now use the DoCmd.OpenReport command to open your report and pass the string in as the criteria parameter.

HTH

Mike

Mike
EchoVue.com
 
Old June 2nd, 2006, 08:51 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks,

I'm working on it now.

-Dave

 
Old June 2nd, 2006, 01:25 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I'm having a problem.

I made the form with two comboboxes that pull the dates(Begin and End) from the date field in my table. When I run the form and select a date from the combobox I get an error message saying that the value entered is invalid.
I thought I had it narrowed down to being the columnwidths property, but it didn't seem to have any effect.
Any ideas on this?

thanks

-Dave

 
Old June 2nd, 2006, 01:37 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

OK - I get this a lot!!! What you want to do, is make sure that the combo boxes are not bound to the table. So under the datatab, delete anything in the data source field. Then under record source click the button with the ... and set up a query that just pulls in the data field.

Let me know how that goes and we can take it from there.

Mike

Mike
EchoVue.com
 
Old June 2nd, 2006, 01:41 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

The other option, would be to change the controls to unbound textboxes and have the user enter the complete date. This would be good if you want a report from 5/1 - 5/30 and perhaps those dates don't occur in the table. Afterwards, I can walk you through ensuring that the dates are valuable.

If you feel really adventurous, I can send you a part of a database that I did recently, that pops up a calendar for the user to pick from, and that way, you ensure that the date is entered in the right format!

Mike
EchoVue.com
 
Old June 2nd, 2006, 02:12 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Mike,

Thanks for replying.

I figured out why I was getting the error.
Somehow the rowsource got set to pull the date column and the ID column. So, I deleted the ID column and now the comboboxes are working fine, as far as that goes.

Am I still going to need to do what you recommended about deleting the record source and building a query? Or do you think it will work like I have it now?
The calendar would be cool, but the field contains the date and the time, so I don't know if it would work.

Thanks again,

Dave

 
Old June 2nd, 2006, 02:18 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Hi Dave,

I probably wouldn't worry about changing the rowsource etc. now. See what you can do as far as now running the report, using a filter. I need to head into a meeting (gotta love those Friday afternoon snoozes!) and I'll check back in after that to see if you need anything else.

Mike

Mike
EchoVue.com
 
Old June 2nd, 2006, 03:02 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Mike,

Hope your meeting was fun.

I'm not sure about how to use a filter. I've been researching it some, but I'm not sure what kind of filter I need to use.
I put some of the code I'm trying to use to this post. I thought maybe you could tell me if I'm on the right track or barking up the wrong tree.
I also just found out that I need to filter using a second criteria. I've put a radio button group on my form to use to select the second criteria. This comes from another field in the same table. The options are 20,40, or both.


Private Sub btnReport_Click()
    Dim strBegin As String
    Dim strEnd As String
    Dim strDoc As String
    Dim strWhere As String

    strDoc = "Floor Requests"
If Len(Me.cboStartDate & "") > 0 And Len(Me.cboEndDate & "") > 0 Then
    ' entries in both
    strWhere = strWhere & " AND Req_Date Between #" & Me.cboStartDate & "# AND #" & Me.cboEndDate & "#"
Else
    If Len(Me.cboStartDate & "") > 0 And Len(Me.cboEndDate & "") = 0 Then
    strWhere = strWhere & " AND Req_Date >= #" & Me.cboStartDate & "#"
Else
    If Len(Me.cboStartDate & "") = 0 And Len(Me.cboEndDate & "") > 0 Then
    strWhere = strWhere & " AND Req_Date <= #" & Me.cboStartDate & "#"
End If
If Len(strWhere & "") = 0 Then
    DoCmd.OpenReport strDoc, acViewPreview
Else
      DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=Mid(strWhere, 6)
End If

End Sub


Thanks for all your help

-Dave

 
Old June 2nd, 2006, 03:52 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Well, I made it through without falling asleep, but I don't know if that was a good thing or a bad thing.

That code is kind of the way I would do it, perhaps if I could offer some changes (it may just be personal preference though)

Code:
Private Sub btnReport_Click()
    Dim strBegin As String
    Dim strEnd As String
    Dim strDoc As String
    Dim strWhere As String

    strDoc = "Floor Requests"      
If Len(Me.cboStartDate & "") > 0 And Len(Me.cboEndDate & "") > 0 Then
    ' entries in both
    strWhere = strWhere & "Req_Date Between #" & Me.cboStartDate & "# AND #" & Me.cboEndDate & "#"
Else
    If Len(Me.cboStartDate & "") > 0 And Len(Me.cboEndDate & "") = 0 Then        
    strWhere = strWhere & "Req_Date >= #" & Me.cboStartDate & "#"
Else
    If Len(Me.cboStartDate & "") = 0 And Len(Me.cboEndDate & "") > 0 Then       
    strWhere = strWhere & "Req_Date <= #" & Me.cboStartDate & "#"
End If
If Len(strWhere & "") = 0 Then   
    DoCmd.OpenReport strDoc, acViewPreview
Else
      DoCmd.OpenReport strDoc, acViewPreview, ,strWhere
End If

End Sub
It's a little cleaner!

Good Luck,

Mike

Mike
EchoVue.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting multiple rows in a flexgrid dfbosse VB How-To 2 May 23rd, 2006 12:18 AM
selecting rows returned by executing a SP dsekar_nat SQL Server 2000 4 May 11th, 2006 11:12 AM
Selecting Fields to be printed on vb6 report marvs Pro VB Databases 0 June 29th, 2005 07:36 PM
Acceptable # of rows in a report bassist695 BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 April 13th, 2005 10:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.