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.
24 1445 Form1
txtStartDate
txtEndDate Query1 -
SELECT *
-
FROM Table1
-
WHERE EventDate BETWEEN Forms!Form1!txtStartDate AND Forms!Form1!txtEndDate;
-
Form1
txtStartDate
txtEndDate Query1 -
SELECT *
-
FROM Table1
-
WHERE EventDate BETWEEN Forms!Form1!txtStartDate AND Forms!Form1!txtEndDate;
-
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
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.
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? -
Private Sub Command38_Click()
-
Dim stDocName
-
Dim stLinkCriteria
-
Dim pstCriteria As String
-
-
-
Select Case frmOptionX
-
-
Case "DateReceived"
-
stDocName = "rptDateReceived"
-
-
If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
-
pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#"
-
-
DoCmd.OpenReport "rptDateReceived", acViewPreview, , pstrCriteria
-
-
Else
-
MsgBox "You must enter two dates"
-
-
End If
-
-
-
Case "DateRepliedOn"
-
-
stDocName = "rptDateRepliedOn"
-
-
-
If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
-
pstrCriteria = "[rptDateRepliedOn] >= # " & [txtFirstDate] & "# and [rptDateRepliedOn]<=#" & [txtEndDate] & "#"
-
-
DoCmd.OpenReport "rptDateRepliedOn", acViewPreview, , pstrCriteria
-
-
Else
-
MsgBox "You must enter two dates"
-
-
End If
-
-
Case "ReplyDeadline"
-
-
If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
-
pstrCriteria = "[ReplyDateline] >= # " & [txtFirstDate] & "# and [ReplyDateline]<=#" & [txtEndDate] & "#"
-
-
DoCmd.OpenReport "rptReplyDateline", acViewPreview, , pstrCriteria
-
-
Else
-
MsgBox "You must enter two dates"
-
-
End Select
-
-
-
End Sub
-
Thanks in advance
That could work but it would be easier just to do: -
Private Sub Command38_Click()
-
Dim stDocName
-
Dim pstrCriteria As String
-
-
stDocName = frmOptionX
-
-
If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
-
pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#"
-
-
DoCmd.OpenReport stDocName, acViewPreview, , pstrCriteria
-
-
Else
-
MsgBox "You must enter two dates"
-
-
End If
-
End Sub
-
Thanks in advance[/quote]
That could work but it would be easier just to do: -
Private Sub Command38_Click()
-
Dim stDocName
-
Dim pstrCriteria As String
-
-
stDocName = frmOptionX
-
-
If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
-
pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#"
-
-
DoCmd.OpenReport stDocName, acViewPreview, , pstrCriteria
-
-
Else
-
MsgBox "You must enter two dates"
-
-
End If
-
End Sub
-
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.
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.
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? -
Private Sub Command48_Click()
-
-
Dim stDocName
-
Dim pstCriteria As String
-
-
-
Select Case frmOptionX
-
-
Case "DateReceived"
-
stDocName = "rptDateReceived"
-
-
If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
-
pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#"
-
-
DoCmd.OpenReport "rptDateReceived", acViewPreview, , pstrCriteria
-
-
Else
-
MsgBox "You must enter two dates"
-
-
End If
-
-
-
Case "DateRepliedOn"
-
-
stDocName = "rptDateRepliedOn"
-
-
-
If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
-
pstrCriteria = "[DateRepliedOn] >= # " & [txtFirstDate] & "# and [DateRepliedOn]<=#" & [txtEndDate] & "#"
-
-
DoCmd.OpenReport "rptDateRepliedOn", acViewPreview, , pstrCriteria
-
-
Else
-
MsgBox "You must enter two dates"
-
-
End If
-
-
Case "ReplyDeadline"
-
-
If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
-
pstrCriteria = "[ReplyDateline] >= # " & [txtFirstDate] & "# and [ReplyDateline]<=#" & [txtEndDate] & "#"
-
-
DoCmd.OpenReport "rptReplyDateline", acViewPreview, , pstrCriteria
-
-
Else
-
MsgBox "You must enter two dates"
-
-
End Select
-
-
-
End Sub
-
Thank you!!
It looks like you fogot an End If on your last case.
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.
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.
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.
Thank you sir, I will start working on it.
No problem, let us know if you run into any problems.
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. -
-
Private Sub Command48_Click()
-
-
-
Dim pstCriteria As String
-
Dim strSelect As String
-
-
-
-
Select Case frmOptionX
-
-
-
Case "rptDateReceived"
-
-
-
If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
-
pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#" & strSelect = "DocumentType = '" & Me.frmTest & "'"
-
-
-
DoCmd.OpenReport "rptDateReceived", acViewPreview, , pstrCriteria, , strSelect
-
-
Else
-
MsgBox "You must enter two dates"
-
-
End If
-
You use Code tags by surrounding it with [ Code=vb ] and [ /Code ] without the spaces between the [ and ].
As for this: - pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#" & strSelect = "DocumentType = '" & Me.frmTest & "'"
-
You can't have two assignments on the same line. But that is moot as you don't need two. -
pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "# AND DocumentType = '" & Me.frmTest & "'"
-
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.
You use Code tags by surrounding it with [ Code=vb ] and [ /Code ] without the spaces between the [ and ].
As for this: - pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#" & strSelect = "DocumentType = '" & Me.frmTest & "'"
-
You can't have two assignments on the same line. But that is moot as you don't need two. -
pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "# AND DocumentType = '" & Me.frmTest & "'"
-
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.
If I wanted to select all I would use: -
pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "# AND DocumentType Like '" & Me.frmTest & "'"
-
And if I wanted all document types, I would have frmTest return *.
If I wanted to select all I would use: -
pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "# AND DocumentType Like '" & Me.frmTest & "'"
-
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.
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.
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. -
-
Dim Criteria As String
-
Dim pstCriteria As String
-
Dim strSelect As String
-
Dim i As Variant
-
-
Criteria = ""
-
For Each i In Me![lstTest2].ItemsSelected
-
If Criteria <> "" Then
-
Criteria = Criteria & " OR "
-
End If
-
Criteria = Criteria & "[DocumentType]='" _
-
& Me![lstTest2].ItemData(i) & "'"
-
Next i
-
-
Me.Filter = Criteria
-
Me.FilterOn = True
-
-
-
-
Select Case frmOptionX
-
-
-
Case "rptDateReceived"
-
-
-
If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
-
pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "# AND DocumentType = '" & Me.lstTest2 & "'"
-
-
-
DoCmd.OpenReport "rptDateReceived", acViewPreview, , pstrCriteria
-
-
Else
-
MsgBox "You must enter two dates"
-
-
End If
-
-
End Select
-
End Sub
-
-
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. -
-
Dim Criteria As String
-
Dim pstCriteria As String
-
Dim strSelect As String
-
Dim i As Variant
-
-
Criteria = ""
-
For Each i In Me![lstTest2].ItemsSelected
-
If Criteria <> "" Then
-
Criteria = Criteria & " OR "
-
End If
-
Criteria = Criteria & "[DocumentType]='" _
-
& Me![lstTest2].ItemData(i) & "'"
-
Next i
-
-
Me.Filter = Criteria
-
Me.FilterOn = True
-
-
-
-
Select Case frmOptionX
-
-
-
Case "rptDateReceived"
-
-
-
If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
-
pstrCriteria = "[DateReceived] >= # " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "# AND DocumentType = '" & Me.lstTest2 & "'"
-
-
-
DoCmd.OpenReport "rptDateReceived", acViewPreview, , pstrCriteria
-
-
Else
-
MsgBox "You must enter two dates"
-
-
End If
-
-
End Select
-
End Sub
-
-
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: - FieldName In ('Value1', 'Value2', 'Value3')
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: - FieldName In ('Value1', 'Value2', 'Value3')
Thank you Sir, howeve I am not sure I understand what you mean with the code below. Thanks again. - FieldName In ('Value1', 'Value2', 'Value3')
[/quote]
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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 =...
|
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...
|
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...
|
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...
|
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);...
|
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,...
|
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...
|
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...
|
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....
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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,...
| |