Date parameter

G

Guest

From form frmUsers i have more then one selected names in lstSelected list
box and date from 'txtFrom', date to 'txtTo'. When i click on button it will
open frmNew form, and this part in my code 'PCreatedDate = between
"Forms!frmNew.txtFrom" and Forms!frmNew.txtTo", i am not sure how use
parameter in my code for date.
Please help me.

Thank you
==============
Private Sub Form_Open(Cancel As Integer)
Dim PCreatedBy As Integer
Dim strRecordSource As String
Dim PCreatedDate As Integer
If CurrentProject.AllForms("frmNew").IsLoaded Then
strRecordSource = "Select * from tblUserInfo where PCreatedBy = '" &
Forms!frmNew.lstSelected & "'"
And PCreatedDate = between "Forms!frmNew.txtFrom" and Forms!frmNew.txtTo"
Me.Form.RecordSource = strRecordSource
End If
End Sub
 
A

Allen Browne

The literal date value in the SQL string needs to be formatted the way JET
expects, and delimited with #.

Const strcJetDate = "\#mm/dd/yyyy\#"

With Forms!frmNew
If IsNull(!lstSelected) Or IsNull(!txtFrom) Or IsNull(!txtTo) Then
MsgBox "Somehing's missing."
Else
strRecordSource = "Select tblUserInfo.* from tblUserInfo " & _
"where (PCreatedBy = """ & !lstSelected & _
""") And (PCreatedDate between " & _
Format(!txtFrom, strcJetDate) & " and " & _
Format(!txtTo, strcJetDate) & ");"
Debug.Print strRecordSource
Me.RecordSource = strRecordSource
End If
End With
 
G

Guest

Thank you so much.

Allen Browne said:
The literal date value in the SQL string needs to be formatted the way JET
expects, and delimited with #.

Const strcJetDate = "\#mm/dd/yyyy\#"

With Forms!frmNew
If IsNull(!lstSelected) Or IsNull(!txtFrom) Or IsNull(!txtTo) Then
MsgBox "Somehing's missing."
Else
strRecordSource = "Select tblUserInfo.* from tblUserInfo " & _
"where (PCreatedBy = """ & !lstSelected & _
""") And (PCreatedDate between " & _
Format(!txtFrom, strcJetDate) & " and " & _
Format(!txtTo, strcJetDate) & ");"
Debug.Print strRecordSource
Me.RecordSource = strRecordSource
End If
End With
 
G

Guest

When i start running your code i've got error msg:
"Run-time error '2757': There was a problem accessing a property or method
of the OLE object."
When i removed date parameter i only able to view data for one user but in
lstSelected list box i have 4 names, it should pull data for 4 users.
I am not sure what i need to do...
Do i need declare 'strcJetDate ', if yes then is 'Dim strcJetDate as ???'
Please help with this code.
Thank you.
 
A

Allen Browne

The line starting with Const is the delaration: you do not need to Dim it as
well.

After entering the code, choose Compile on the Debug window. Fix any errors,
and repeat until it compiles okay.

I assume that you have a form named frmNew, the form is open, and it has a
listbox named lstSelected. If this is a multi-select listbox, you need
different code to loop through its ItemsSelected collection like this:
http://allenbrowne.com/ser-50.html
If it is not a multi-select list box, and you select one record, only the
matching record will be included. If you select no record, the list box is
null, and you need to NOT include this in your WHERE clause. Test using
IsNull().

Error 2757 is quite a generic one. You will need to note which line
generates that error.
 
G

Guest

Hello,
Thank you so much for helping me.
My lstSelected list box in my form is Row Source Type = "Value List", Row
Source = nothing and Control Source ="nothing", only one column in the list
box. My first step is move from lstAvailable list box to lstSelected then if
for example i have 5 names in a 'lstSelected' lst box then i click on button
"Preview Report", i should have all info for 5 users. I am using your code
and i did exactly what you said in your notes (1-4).For Record source in a
report shoul be just table name "tblNames" or "Select * from tblNames" ??? I
did add text box to the report and entered for control source:
=[Report].[OpenArgs]. Also i did compile system, it's clean now.
But still my preview button it's not working. May be I changed the code
incorrectly. here is the code:

Private Sub cmdPreview_Click()

On Error GoTo Err_Handler
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.

strDelim = """" 'Delimiter appropriate to field type. See
note 1.
strDoc = "rptNames"

'Loop through the ItemsSelected in the list box.
With Me.lstSelected
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
'Build up the description from the text in the visible
column. See note 2.
strDescrip = strDescrip & """" & .Column(1, varItem) & """, "
End If
Next
End With

'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[Names] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Categories: " & Left$(strDescrip, lngLen)
End If
End If

If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If

DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere
' I did drop the OpenArgs:=strDescrip

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler

End Sub
====
Please let me know what i am doing wrong.
Thank you.
 
A

Allen Browne

Suggestions:

1. Temporarily comment out the error handler by adding a single quote to
this line:
'On Error GoTo Err_Handler
Then tell us which line is giving the error, and exactly what the error
message says.

2. Just before the OpenReport line (near the end), add:
Debug.Print strWhere
When the report opens, open the Immediate Window (Ctrl+G) and look at what
comes out. It must look like the WHERE clause in a query. Are the brackets
and spaces correct? Are each of the user names inside quotes? Post the
string here if you are not sure.

3. When you open your table in design view, what data type is the Names
field?

Regarding your questions:
- If the RowSourceType of your listbox is Value List, leaving the RowSource
property blank is correct.

- OpenArgs works only in Access 2002 or 2003 (from memory), so leaving it
out is a good idea if you are working with earlier versions.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

GGill said:
Hello,
Thank you so much for helping me.
My lstSelected list box in my form is Row Source Type = "Value List", Row
Source = nothing and Control Source ="nothing", only one column in the
list
box. My first step is move from lstAvailable list box to lstSelected then
if
for example i have 5 names in a 'lstSelected' lst box then i click on
button
"Preview Report", i should have all info for 5 users. I am using your code
and i did exactly what you said in your notes (1-4).For Record source in a
report shoul be just table name "tblNames" or "Select * from tblNames"
??? I
did add text box to the report and entered for control source:
=[Report].[OpenArgs]. Also i did compile system, it's clean now.
But still my preview button it's not working. May be I changed the code
incorrectly. here is the code:

Private Sub cmdPreview_Click()

On Error GoTo Err_Handler
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.

strDelim = """" 'Delimiter appropriate to field type. See
note 1.
strDoc = "rptNames"

'Loop through the ItemsSelected in the list box.
With Me.lstSelected
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
'Build up the description from the text in the visible
column. See note 2.
strDescrip = strDescrip & """" & .Column(1, varItem) & """,
"
End If
Next
End With

'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[Names] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Categories: " & Left$(strDescrip, lngLen)
End If
End If

If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If

DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere
' I did drop the OpenArgs:=strDescrip

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler

End Sub
====
Please let me know what i am doing wrong.
Thank you.

Allen Browne said:
The line starting with Const is the delaration: you do not need to Dim it
as
well.

After entering the code, choose Compile on the Debug window. Fix any
errors,
and repeat until it compiles okay.

I assume that you have a form named frmNew, the form is open, and it has
a
listbox named lstSelected. If this is a multi-select listbox, you need
different code to loop through its ItemsSelected collection like this:
http://allenbrowne.com/ser-50.html
If it is not a multi-select list box, and you select one record, only the
matching record will be included. If you select no record, the list box
is
null, and you need to NOT include this in your WHERE clause. Test using
IsNull().

Error 2757 is quite a generic one. You will need to note which line
generates that error.
 
G

Guest

Hello,
When i moved 2 names from lstAvailable list box to lstSelected and open
report, in my view report i have all records listed from table, but i am
trying to view only two records, but if one of those names highlighted in
sltSelected list box then it will open for one name which was highlighted.
Here is what i have when i open Immediate Window : [PCreatedBy] IN ("kate")
But in my lstSelected list box i have 2 names. In my form in lstSelected
list box i have only one column and "Names" field data type is text.
I am not sure what i need to do???
Thank you.
================
Private Sub cmdPreview_Click()
'On Error GoTo Err_Handler
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.

strDelim = """" 'Delimiter appropriate to field type. See
note 1.
strDoc = "rptReport1"

With Me.lstSelected
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
strDescrip = strDescrip & """" & .Column(1, varItem) & """, "
End If
Next
End With
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[Names] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Categories: " & Left$(strDescrip, lngLen)
End If
End If
If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If
Debug.Print strWhere
DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler

End Sub
========================================

Allen Browne said:
Suggestions:

1. Temporarily comment out the error handler by adding a single quote to
this line:
'On Error GoTo Err_Handler
Then tell us which line is giving the error, and exactly what the error
message says.

2. Just before the OpenReport line (near the end), add:
Debug.Print strWhere
When the report opens, open the Immediate Window (Ctrl+G) and look at what
comes out. It must look like the WHERE clause in a query. Are the brackets
and spaces correct? Are each of the user names inside quotes? Post the
string here if you are not sure.

3. When you open your table in design view, what data type is the Names
field?

Regarding your questions:
- If the RowSourceType of your listbox is Value List, leaving the RowSource
property blank is correct.

- OpenArgs works only in Access 2002 or 2003 (from memory), so leaving it
out is a good idea if you are working with earlier versions.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

GGill said:
Hello,
Thank you so much for helping me.
My lstSelected list box in my form is Row Source Type = "Value List", Row
Source = nothing and Control Source ="nothing", only one column in the
list
box. My first step is move from lstAvailable list box to lstSelected then
if
for example i have 5 names in a 'lstSelected' lst box then i click on
button
"Preview Report", i should have all info for 5 users. I am using your code
and i did exactly what you said in your notes (1-4).For Record source in a
report shoul be just table name "tblNames" or "Select * from tblNames"
??? I
did add text box to the report and entered for control source:
=[Report].[OpenArgs]. Also i did compile system, it's clean now.
But still my preview button it's not working. May be I changed the code
incorrectly. here is the code:

Private Sub cmdPreview_Click()

On Error GoTo Err_Handler
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.

strDelim = """" 'Delimiter appropriate to field type. See
note 1.
strDoc = "rptNames"

'Loop through the ItemsSelected in the list box.
With Me.lstSelected
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
'Build up the description from the text in the visible
column. See note 2.
strDescrip = strDescrip & """" & .Column(1, varItem) & """,
"
End If
Next
End With

'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[Names] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Categories: " & Left$(strDescrip, lngLen)
End If
End If

If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If

DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere
' I did drop the OpenArgs:=strDescrip

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler

End Sub
====
Please let me know what i am doing wrong.
Thank you.

Allen Browne said:
The line starting with Const is the delaration: you do not need to Dim it
as
well.

After entering the code, choose Compile on the Debug window. Fix any
errors,
and repeat until it compiles okay.

I assume that you have a form named frmNew, the form is open, and it has
a
listbox named lstSelected. If this is a multi-select listbox, you need
different code to loop through its ItemsSelected collection like this:
http://allenbrowne.com/ser-50.html
If it is not a multi-select list box, and you select one record, only the
matching record will be included. If you select no record, the list box
is
null, and you need to NOT include this in your WHERE clause. Test using
IsNull().

Error 2757 is quite a generic one. You will need to note which line
generates that error.

When i start running your code i've got error msg:
"Run-time error '2757': There was a problem accessing a property or
method
of the OLE object."
When i removed date parameter i only able to view data for one user but
in
lstSelected list box i have 4 names, it should pull data for 4 users.
I am not sure what i need to do...
Do i need declare 'strcJetDate ', if yes then is 'Dim strcJetDate as
???'
Please help with this code.
Thank you.

:

The literal date value in the SQL string needs to be formatted the way
JET
expects, and delimited with #.

Const strcJetDate = "\#mm/dd/yyyy\#"

With Forms!frmNew
If IsNull(!lstSelected) Or IsNull(!txtFrom) Or IsNull(!txtTo) Then
MsgBox "Somehing's missing."
Else
strRecordSource = "Select tblUserInfo.* from tblUserInfo " & _
"where (PCreatedBy = """ & !lstSelected & _
""") And (PCreatedDate between " & _
Format(!txtFrom, strcJetDate) & " and " & _
Format(!txtTo, strcJetDate) & ");"
Debug.Print strRecordSource
Me.RecordSource = strRecordSource
End If
End With

From form frmUsers i have more then one selected names in
lstSelected
list
box and date from 'txtFrom', date to 'txtTo'. When i click on button
it
will
open frmNew form, and this part in my code 'PCreatedDate = between
"Forms!frmNew.txtFrom" and Forms!frmNew.txtTo", i am not sure how
use
parameter in my code for date.
Please help me.

Thank you
==============
Private Sub Form_Open(Cancel As Integer)
Dim PCreatedBy As Integer
Dim strRecordSource As String
Dim PCreatedDate As Integer
If CurrentProject.AllForms("frmNew").IsLoaded Then
strRecordSource = "Select * from tblUserInfo where PCreatedBy =
'" &
Forms!frmNew.lstSelected & "'"
And PCreatedDate = between "Forms!frmNew.txtFrom" and
Forms!frmNew.txtTo"
Me.Form.RecordSource = strRecordSource
End If
End Sub
 
A

Allen Browne

Sorry: I'm getting lost with this thread.

I do not understand why the code is returning only one name in strWhere when
you have 2 names selected in the list box.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

GGill said:
Hello,
When i moved 2 names from lstAvailable list box to lstSelected and open
report, in my view report i have all records listed from table, but i am
trying to view only two records, but if one of those names highlighted in
sltSelected list box then it will open for one name which was highlighted.
Here is what i have when i open Immediate Window : [PCreatedBy] IN
("kate")
But in my lstSelected list box i have 2 names. In my form in lstSelected
list box i have only one column and "Names" field data type is text.
I am not sure what i need to do???
Thank you.
================
Private Sub cmdPreview_Click()
'On Error GoTo Err_Handler
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.

strDelim = """" 'Delimiter appropriate to field type. See
note 1.
strDoc = "rptReport1"

With Me.lstSelected
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
strDescrip = strDescrip & """" & .Column(1, varItem) & """,
"
End If
Next
End With
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[Names] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Categories: " & Left$(strDescrip, lngLen)
End If
End If
If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If
Debug.Print strWhere
DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler

End Sub
========================================

Allen Browne said:
Suggestions:

1. Temporarily comment out the error handler by adding a single quote to
this line:
'On Error GoTo Err_Handler
Then tell us which line is giving the error, and exactly what the error
message says.

2. Just before the OpenReport line (near the end), add:
Debug.Print strWhere
When the report opens, open the Immediate Window (Ctrl+G) and look at
what
comes out. It must look like the WHERE clause in a query. Are the
brackets
and spaces correct? Are each of the user names inside quotes? Post the
string here if you are not sure.

3. When you open your table in design view, what data type is the Names
field?

Regarding your questions:
- If the RowSourceType of your listbox is Value List, leaving the
RowSource
property blank is correct.

- OpenArgs works only in Access 2002 or 2003 (from memory), so leaving it
out is a good idea if you are working with earlier versions.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

GGill said:
Hello,
Thank you so much for helping me.
My lstSelected list box in my form is Row Source Type = "Value List",
Row
Source = nothing and Control Source ="nothing", only one column in the
list
box. My first step is move from lstAvailable list box to lstSelected
then
if
for example i have 5 names in a 'lstSelected' lst box then i click on
button
"Preview Report", i should have all info for 5 users. I am using your
code
and i did exactly what you said in your notes (1-4).For Record source
in a
report shoul be just table name "tblNames" or "Select * from tblNames"
??? I
did add text box to the report and entered for control source:
=[Report].[OpenArgs]. Also i did compile system, it's clean now.
But still my preview button it's not working. May be I changed the code
incorrectly. here is the code:

Private Sub cmdPreview_Click()

On Error GoTo Err_Handler
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.

strDelim = """" 'Delimiter appropriate to field type. See
note 1.
strDoc = "rptNames"

'Loop through the ItemsSelected in the list box.
With Me.lstSelected
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
'Build up the description from the text in the visible
column. See note 2.
strDescrip = strDescrip & """" & .Column(1, varItem) &
""",
"
End If
Next
End With

'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[Names] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Categories: " & Left$(strDescrip, lngLen)
End If
End If

If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If

DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere
' I did drop the OpenArgs:=strDescrip

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler

End Sub
====
Please let me know what i am doing wrong.
Thank you.

:

The line starting with Const is the delaration: you do not need to Dim
it
as
well.

After entering the code, choose Compile on the Debug window. Fix any
errors,
and repeat until it compiles okay.

I assume that you have a form named frmNew, the form is open, and it
has
a
listbox named lstSelected. If this is a multi-select listbox, you need
different code to loop through its ItemsSelected collection like this:
http://allenbrowne.com/ser-50.html
If it is not a multi-select list box, and you select one record, only
the
matching record will be included. If you select no record, the list
box
is
null, and you need to NOT include this in your WHERE clause. Test
using
IsNull().

Error 2757 is quite a generic one. You will need to note which line
generates that error.

When i start running your code i've got error msg:
"Run-time error '2757': There was a problem accessing a property or
method
of the OLE object."
When i removed date parameter i only able to view data for one user
but
in
lstSelected list box i have 4 names, it should pull data for 4
users.
I am not sure what i need to do...
Do i need declare 'strcJetDate ', if yes then is 'Dim strcJetDate
as
???'
Please help with this code.
Thank you.

:

The literal date value in the SQL string needs to be formatted the
way
JET
expects, and delimited with #.

Const strcJetDate = "\#mm/dd/yyyy\#"

With Forms!frmNew
If IsNull(!lstSelected) Or IsNull(!txtFrom) Or IsNull(!txtTo)
Then
MsgBox "Somehing's missing."
Else
strRecordSource = "Select tblUserInfo.* from tblUserInfo "
& _
"where (PCreatedBy = """ & !lstSelected & _
""") And (PCreatedDate between " & _
Format(!txtFrom, strcJetDate) & " and " & _
Format(!txtTo, strcJetDate) & ");"
Debug.Print strRecordSource
Me.RecordSource = strRecordSource
End If
End With

From form frmUsers i have more then one selected names in
lstSelected
list
box and date from 'txtFrom', date to 'txtTo'. When i click on
button
it
will
open frmNew form, and this part in my code 'PCreatedDate =
between
"Forms!frmNew.txtFrom" and Forms!frmNew.txtTo", i am not sure how
use
parameter in my code for date.
Please help me.

Thank you
==============
Private Sub Form_Open(Cancel As Integer)
Dim PCreatedBy As Integer
Dim strRecordSource As String
Dim PCreatedDate As Integer
If CurrentProject.AllForms("frmNew").IsLoaded Then
strRecordSource = "Select * from tblUserInfo where PCreatedBy
=
'" &
Forms!frmNew.lstSelected & "'"
And PCreatedDate = between "Forms!frmNew.txtFrom" and
Forms!frmNew.txtTo"
Me.Form.RecordSource = strRecordSource
End If
End Sub
 
G

Guest

For example i have two names in my 'lstSelected' list box . If you select in
lstSelcted list box one name it will open report only with one record for
one selected name but if is nothing selected it will open report with all
data from table.
If you would like i can send you database it's just with 1 Table, 1 form and
one report.
Please let me know
It should open report with two records without selecting then in
lstSelected box.

Thank you.
 
A

Allen Browne

Please do not send the database. Hope you can understand that if we opened
everyone's database, we would get no work done at all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top