473,386 Members | 1,764 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,386 software developers and data experts.

problem with 2 text boxes and 2 list boxes

48
I am using Access 2007 and I have two list boxes where the user is suppose to type a range of dates.
Then I have a list box so the user can select wheter he/she wants to pull letters or proposals.
Finally I have a list box to see what report the user wants to open (date document was received, deadline, date when the doc. was replied).

I want the user to be able to type the dates on the textboxes select a report and type of document and a report will be generated with those choosen fields.

Do someone has an example code for this situation, I need it badly.

Thanks in advance.
Oct 15 '07 #1
24 1445
Rabbit
12,516 Expert Mod 8TB
Form1
txtStartDate
txtEndDate

Query1
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM Table1
  3. WHERE EventDate BETWEEN Forms!Form1!txtStartDate AND Forms!Form1!txtEndDate;
  4.  
Oct 15 '07 #2
margot
48
Form1
txtStartDate
txtEndDate

Query1
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM Table1
  3. WHERE EventDate BETWEEN Forms!Form1!txtStartDate AND Forms!Form1!txtEndDate;
  4.  

Thank you Sir;
However I am not too familiarize with sql code, is that all the code that I need? and how is that related with the first part. Do I only need to declare the text boxes for the first part?
Thanks again
Oct 16 '07 #3
Rabbit
12,516 Expert Mod 8TB
Thank you Sir;
However I am not too familiarize with sql code, is that all the code that I need? and how is that related with the first part. Do I only need to declare the text boxes for the first part?
Thanks again
This is only an inkling of what you need. But it's enough to get you started on creating a report that uses a query that pulls its criteria from a form. Opening the report is a simple matter of running DoCmd.OpenReport from an event of your choosing.
Oct 16 '07 #4
margot
48
This is only an inkling of what you need. But it's enough to get you started on creating a report that uses a query that pulls its criteria from a form. Opening the report is a simple matter of running DoCmd.OpenReport from an event of your choosing.
Thank you sir. However can I do somehting like the code below using cases for a combo box?
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command38_Click()
  2. Dim stDocName
  3. Dim stLinkCriteria
  4. Dim pstCriteria As String
  5.  
  6.  
  7. Select Case frmOptionX
  8.  
  9.     Case "DateReceived"
  10.         stDocName = "rptDateReceived"
  11.  
  12.         If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
  13.             pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#"
  14.  
  15.         DoCmd.OpenReport "rptDateReceived", acViewPreview, , pstrCriteria
  16.  
  17.             Else
  18.                 MsgBox "You must enter two dates"
  19.  
  20.   End If
  21.  
  22.  
  23.     Case "DateRepliedOn"
  24.  
  25.         stDocName = "rptDateRepliedOn"
  26.  
  27.  
  28.           If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
  29.               pstrCriteria = "[rptDateRepliedOn] >= # " & [txtFirstDate] & "# and [rptDateRepliedOn]<=#" & [txtEndDate] & "#"
  30.  
  31.             DoCmd.OpenReport "rptDateRepliedOn", acViewPreview, , pstrCriteria
  32.  
  33.         Else
  34.              MsgBox "You must enter two dates"
  35.  
  36.   End If
  37.  
  38.     Case "ReplyDeadline"
  39.  
  40.          If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
  41.               pstrCriteria = "[ReplyDateline] >= # " & [txtFirstDate] & "# and [ReplyDateline]<=#" & [txtEndDate] & "#"
  42.  
  43.             DoCmd.OpenReport "rptReplyDateline", acViewPreview, , pstrCriteria
  44.  
  45.         Else
  46.              MsgBox "You must enter two dates"
  47.  
  48.     End Select
  49.  
  50.  
  51. End Sub
  52.  
Thanks in advance
Oct 18 '07 #5
Rabbit
12,516 Expert Mod 8TB
That could work but it would be easier just to do:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command38_Click()
  2. Dim stDocName
  3. Dim pstrCriteria As String
  4.  
  5.         stDocName = frmOptionX
  6.  
  7.         If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
  8.             pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#"
  9.  
  10.         DoCmd.OpenReport stDocName, acViewPreview, , pstrCriteria
  11.  
  12.             Else
  13.                 MsgBox "You must enter two dates"
  14.  
  15.   End If
  16. End Sub
  17.  
Thanks in advance[/quote]
Oct 18 '07 #6
margot
48
That could work but it would be easier just to do:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command38_Click()
  2. Dim stDocName
  3. Dim pstrCriteria As String
  4.  
  5.         stDocName = frmOptionX
  6.  
  7.         If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
  8.             pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#"
  9.  
  10.         DoCmd.OpenReport stDocName, acViewPreview, , pstrCriteria
  11.  
  12.             Else
  13.                 MsgBox "You must enter two dates"
  14.  
  15.   End If
  16. End Sub
  17.  
Thanks in advance
[/quote]

Thank you. This is great. However this will only work for one report since pstrCriteria = "[DateReceived]" will change for each report. For instance "[DateReceived] " will change for "RepliedOn" and "RepliedDeadline". How can I fix this small problem.

Thank you so much.
Oct 18 '07 #7
Rabbit
12,516 Expert Mod 8TB
Oh, I didn't realize the fields were named differently. In that case, then yes, you would have to use the Case statement that you used earlier.
Oct 18 '07 #8
margot
48
Oh, I didn't realize the fields were named differently. In that case, then yes, you would have to use the Case statement that you used earlier.
Thank you. However, when I run the code below with the cases I get an error "End Select without Select Case." My question is, do i need to declare the case differently? or what am I doing wrong?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command48_Click()
  2.  
  3. Dim stDocName
  4. Dim pstCriteria As String
  5.  
  6.  
  7. Select Case frmOptionX
  8.  
  9.     Case "DateReceived"
  10.         stDocName = "rptDateReceived"
  11.  
  12.         If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
  13.             pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#"
  14.  
  15.         DoCmd.OpenReport "rptDateReceived", acViewPreview, , pstrCriteria
  16.  
  17.             Else
  18.                 MsgBox "You must enter two dates"
  19.  
  20.   End If
  21.  
  22.  
  23.     Case "DateRepliedOn"
  24.  
  25.         stDocName = "rptDateRepliedOn"
  26.  
  27.  
  28.           If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
  29.               pstrCriteria = "[DateRepliedOn] >= # " & [txtFirstDate] & "# and [DateRepliedOn]<=#" & [txtEndDate] & "#"
  30.  
  31.             DoCmd.OpenReport "rptDateRepliedOn", acViewPreview, , pstrCriteria
  32.  
  33.         Else
  34.              MsgBox "You must enter two dates"
  35.  
  36.   End If
  37.  
  38.     Case "ReplyDeadline"
  39.  
  40.          If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
  41.               pstrCriteria = "[ReplyDateline] >= # " & [txtFirstDate] & "# and [ReplyDateline]<=#" & [txtEndDate] & "#"
  42.  
  43.             DoCmd.OpenReport "rptReplyDateline", acViewPreview, , pstrCriteria
  44.  
  45.         Else
  46.              MsgBox "You must enter two dates"
  47.  
  48.     End Select
  49.  
  50.  
  51. End Sub
  52.  
Thank you!!
Oct 18 '07 #9
Rabbit
12,516 Expert Mod 8TB
It looks like you fogot an End If on your last case.
Oct 18 '07 #10
margot
48
It looks like you fogot an End If on your last case.
Thank you very much, it is working now! One more question. If I want to add 2 checkboxes so the user can select a date, the drop down, and a check box and the report will be generated. Is there a way that I can add the check box to this code?
Thank you again.
Oct 19 '07 #11
Rabbit
12,516 Expert Mod 8TB
Thank you very much, it is working now! One more question. If I want to add 2 checkboxes so the user can select a date, the drop down, and a check box and the report will be generated. Is there a way that I can add the check box to this code?
Thank you again.
Yes, how you do it depends on what those checkboxes represent. But there's no reason why you can't incorporate it into the code.
Oct 19 '07 #12
margot
48
Yes, how you do it depends on what those checkboxes represent. But there's no reason why you can't incorporate it into the code.
Thank you sir, I will start working on it.
Oct 19 '07 #13
Rabbit
12,516 Expert Mod 8TB
Thank you sir, I will start working on it.
No problem, let us know if you run into any problems.
Oct 19 '07 #14
margot
48
No problem, let us know if you run into any problems.
I added a new ListBox so the user needs to select letter, proposal, or all. So I declared strSelect and gave the selection to that variable. However when I open it, it will open the report but it will not show me any information. Thank you for your time.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command48_Click()
  3.  
  4.  
  5. Dim pstCriteria As String
  6. Dim strSelect As String
  7.  
  8.  
  9.  
  10. Select Case frmOptionX
  11.  
  12.  
  13.     Case "rptDateReceived"
  14.  
  15.  
  16.         If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
  17.             pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#" & strSelect = "DocumentType = '" & Me.frmTest & "'"
  18.  
  19.  
  20.         DoCmd.OpenReport "rptDateReceived", acViewPreview, , pstrCriteria, , strSelect
  21.  
  22.             Else
  23.                 MsgBox "You must enter two dates"
  24.  
  25.   End If
  26.  
Oct 22 '07 #15
Rabbit
12,516 Expert Mod 8TB
You use Code tags by surrounding it with [ Code=vb ] and [ /Code ] without the spaces between the [ and ].

As for this:
Expand|Select|Wrap|Line Numbers
  1. pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#" & strSelect = "DocumentType = '" & Me.frmTest & "'"
  2.  
You can't have two assignments on the same line. But that is moot as you don't need two.

Expand|Select|Wrap|Line Numbers
  1. pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "# AND DocumentType = '" & Me.frmTest & "'"
  2.  
Also, a note about naming conventions. I usually reserve the frm keyword when naming forms. If it's a listbox I usually use lst. Using frm is confusing as people might take it to mean that you're trying to return the value of a form.
Oct 22 '07 #16
margot
48
You use Code tags by surrounding it with [ Code=vb ] and [ /Code ] without the spaces between the [ and ].

As for this:
Expand|Select|Wrap|Line Numbers
  1. pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#" & strSelect = "DocumentType = '" & Me.frmTest & "'"
  2.  
You can't have two assignments on the same line. But that is moot as you don't need two.

Expand|Select|Wrap|Line Numbers
  1. pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "# AND DocumentType = '" & Me.frmTest & "'"
  2.  
Also, a note about naming conventions. I usually reserve the frm keyword when naming forms. If it's a listbox I usually use lst. Using frm is confusing as people might take it to mean that you're trying to return the value of a form.
Thank you!! However is there a way that I can select more than one option? Because if I want to select ALL how would I do that??

THanks again.
Oct 23 '07 #17
Rabbit
12,516 Expert Mod 8TB
If I wanted to select all I would use:
Expand|Select|Wrap|Line Numbers
  1. pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "# AND DocumentType Like '" & Me.frmTest & "'"
  2.  
And if I wanted all document types, I would have frmTest return *.
Oct 23 '07 #18
margot
48
If I wanted to select all I would use:
Expand|Select|Wrap|Line Numbers
  1. pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "# AND DocumentType Like '" & Me.frmTest & "'"
  2.  
And if I wanted all document types, I would have frmTest return *.
Thank you sir. However, I cannot select more than one option even if I do Shit and try to select more than one option. It will only return the value of one option.
Thabk you.
Oct 29 '07 #19
Rabbit
12,516 Expert Mod 8TB
Selecting all and selecting some are different problems. With a select some, you need a multi-select list box. You'll need to create a comma delimited string by looping through the selections in the list box. And in your criteria you'll use the In keyword.
Oct 29 '07 #20
margot
48
Selecting all and selecting some are different problems. With a select some, you need a multi-select list box. You'll need to create a comma delimited string by looping through the selections in the list box. And in your criteria you'll use the In keyword.
Thank you Sir. This is what I did following your advise. I do not get any errors but it does not work properly. It will open the report but blank. Could you please help. Thank you so much.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim Criteria As String
  3. Dim pstCriteria As String
  4. Dim strSelect As String
  5. Dim i As Variant
  6.  
  7.    Criteria = ""
  8.    For Each i In Me![lstTest2].ItemsSelected
  9.       If Criteria <> "" Then
  10.          Criteria = Criteria & " OR "
  11.       End If
  12.       Criteria = Criteria & "[DocumentType]='" _
  13.        & Me![lstTest2].ItemData(i) & "'"
  14.    Next i
  15.  
  16.    Me.Filter = Criteria
  17.    Me.FilterOn = True
  18.  
  19.  
  20.  
  21. Select Case frmOptionX
  22.  
  23.  
  24.     Case "rptDateReceived"
  25.  
  26.  
  27.              If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
  28.               pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "# AND DocumentType = '" & Me.lstTest2 & "'"
  29.  
  30.  
  31.         DoCmd.OpenReport "rptDateReceived", acViewPreview, , pstrCriteria
  32.  
  33.             Else
  34.                 MsgBox "You must enter two dates"
  35.  
  36.    End If
  37.  
  38.   End Select
  39. End Sub
  40.  
  41.  
Oct 29 '07 #21
Rabbit
12,516 Expert Mod 8TB
Thank you Sir. This is what I did following your advise. I do not get any errors but it does not work properly. It will open the report but blank. Could you please help. Thank you so much.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim Criteria As String
  3. Dim pstCriteria As String
  4. Dim strSelect As String
  5. Dim i As Variant
  6.  
  7.    Criteria = ""
  8.    For Each i In Me![lstTest2].ItemsSelected
  9.       If Criteria <> "" Then
  10.          Criteria = Criteria & " OR "
  11.       End If
  12.       Criteria = Criteria & "[DocumentType]='" _
  13.        & Me![lstTest2].ItemData(i) & "'"
  14.    Next i
  15.  
  16.    Me.Filter = Criteria
  17.    Me.FilterOn = True
  18.  
  19.  
  20.  
  21. Select Case frmOptionX
  22.  
  23.  
  24.     Case "rptDateReceived"
  25.  
  26.  
  27.              If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
  28.               pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "# AND DocumentType = '" & Me.lstTest2 & "'"
  29.  
  30.  
  31.         DoCmd.OpenReport "rptDateReceived", acViewPreview, , pstrCriteria
  32.  
  33.             Else
  34.                 MsgBox "You must enter two dates"
  35.  
  36.    End If
  37.  
  38.   End Select
  39. End Sub
  40.  
  41.  
When using the Code tags, you don't put spaces between the brackets [ ].

There are a few things wrong with this.

1) You're using the Filter property of the form, this has no effect on a report.
2) You have multiple criteria strings but you only use one of them in your OpenReport.
3) Your string is constructed impropery. It should be of the format:
Expand|Select|Wrap|Line Numbers
  1. FieldName In ('Value1', 'Value2', 'Value3')
Oct 29 '07 #22
margot
48
When using the Code tags, you don't put spaces between the brackets [ ].

There are a few things wrong with this.

1) You're using the Filter property of the form, this has no effect on a report.
2) You have multiple criteria strings but you only use one of them in your OpenReport.
3) Your string is constructed impropery. It should be of the format:
Expand|Select|Wrap|Line Numbers
  1. FieldName In ('Value1', 'Value2', 'Value3')
Thank you Sir, howeve I am not sure I understand what you mean with the code below. Thanks again.
Expand|Select|Wrap|Line Numbers
  1. FieldName In ('Value1', 'Value2', 'Value3')
[/quote]
Oct 30 '07 #23
Rabbit
12,516 Expert Mod 8TB
That's what your criteria string should look like after you've looped through your listbox to build it. What you currently have is incorrect. It's not that the syntax is wrong, it'll work, but if there's too many selections, your string will become too long.
Oct 30 '07 #24
margot
48
That's what your criteria string should look like after you've looped through your listbox to build it. What you currently have is incorrect. It's not that the syntax is wrong, it'll work, but if there's too many selections, your string will become too long.
Ok thank you Sir. I will try to fix it.
Nov 6 '07 #25

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

Similar topics

2
by: Marc | last post by:
Hi all, I was using Tkinter.IntVar() to store values from a large list of parts that I pulled from a list. This is the code to initialize the instances: def initVariables(self): self.e =...
2
by: Jeff | last post by:
Hello All: What I am trying to do is bind a textbox (really several text boxes) based on a list box selection. Basically what I'm dealing with are two tables with a 1 to 1 relationship. I...
4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
4
by: Amy Snyder | last post by:
I have a webform that has a listbox and two textboxes. The style property of the text boxes are: style="DISPLAY: none" Based on the selection made in the listbox, one or both textboxes are...
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
3
by: deena22 | last post by:
hello, i'm using 'Access database' and VB 6.0. My database is named ' timesheet' and it contains a table named 'tabletimesheet'. The table contain the following fields: 'staffname, stafftype,...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
7
by: ljungers | last post by:
Have Form-1 with 3 text boxes and 1 command button. With any of the 3 boxes filled out and button is clicked, a Macro is performed that Opens a Query that has a WHERE clause that uses the 3 test...
12
by: ljungers | last post by:
I'm on the home streach of my project and found that my "Reset for New Search" command button not working as desired. What should happen is that when the button is clicked a Event Procedure is run....
1
by: skyson2ye | last post by:
Hi, guys: I have written a piece of code which utilizes Javascript in PHP to create a three level dynamic list box(Country, States/Province, Market). However, I have encountered a strange problem,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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,...

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.