Date Range combined with Parameter

G

Guest

Hello,

I want to make a form where I can select a project and see the entered
workload in a subform (that I already did and gives me no problem).

But here is the deal:
I want to add a button that goes to a report with only that specific project
and his date ranged workload.

So I think that I have to combine date range and a parameter.
Can someone help me?

ps: I know that I have to make a From with two unbound text boxes to enter
the desired date range. But I don't know what to add in the OK button (click
event procedure).
 
G

Guest

You need to add the filter to the Where condition of the OpenReport command
line, something like

Dim MyCondition as String
MyCondition = "[ProjetcNum] = " & Me.[ProjNum] & " And [DateFieldName]
Between #" & Me.[StartDate] & "# And #" & Me.[EndDate] & "#"
Docmd.OpenReport "ReportName" , , , MyCondition

===============
If the projNum field type is text then you need to change the where
condition to
MyCondition = "[ProjetcNum] = '" & Me.[ProjNum] & "' And [DateFieldName]
Between #" & Me.[StartDate] & "# And #" & Me.[EndDate] & "#"
==============
StartDate And EndDate are the Date text boxes in the form.
 
G

Guest

Hello,

I tried what you did, and it sounds all very logical but it doesn't work
when I trie it.

this is what I did:
in the form I was talking about I made a button and used your code for the
event procedure on click

--> this is what I have know
Private Sub Command8_Click()
Dim MyCondition As String
MyCondition = "[ProjectID] = " & Me.[ProjectID] & " And [Date Range]"
Between "#" & Me.[BeginDate] & "# And #" & Me.[EndDate] & "#"
DoCmd.OpenReport "Rep_workload", , , MyCondition
End Sub

But this doesn't work
ps: my form with the unbound boxes is called Date Range
 
G

Guest

Try

Private Sub Command8_Click()
Dim MyCondition As String
MyCondition = "[ProjectID] = " & Me.[ProjectID] & " And [Date Range] Between
#" & Me.[BeginDate] & "# And #" & Me.[EndDate] & "#"
DoCmd.OpenReport "Rep_workload", , , MyCondition
End Sub
 
G

Guest

Sorry,

I'm back,
I tried thes adjustements but he gave a syntax error when I tried it.
He also displayed the thrid line red. (Between ....)
 
G

Guest

Make sure that the where condition is in one line, or try this

Private Sub Command8_Click()
Dim MyCondition As String
MyCondition = "[ProjectID] = " & Me.[ProjectID] & " And [Date Range] " & _
" Between #" & Me.[BeginDate] & "# And #" & Me.[EndDate] & "#"
DoCmd.OpenReport "Rep_workload", , , MyCondition
End Sub
 
G

Gina Whipp

David,

I think Ofer meant for the MyCondition to be ALL on one line... (sometimes
these messages wrap) ...is that what you have?

HTH,
Gina Whipp

Ofer Cohen said:
Try

Private Sub Command8_Click()
Dim MyCondition As String
MyCondition = "[ProjectID] = " & Me.[ProjectID] & " And [Date Range]
Between
#" & Me.[BeginDate] & "# And #" & Me.[EndDate] & "#"
DoCmd.OpenReport "Rep_workload", , , MyCondition
End Sub

--
Good Luck
BS"D


David said:
Hello,

I tried what you did, and it sounds all very logical but it doesn't work
when I trie it.

this is what I did:
in the form I was talking about I made a button and used your code for
the
event procedure on click

--> this is what I have know
Private Sub Command8_Click()
Dim MyCondition As String
MyCondition = "[ProjectID] = " & Me.[ProjectID] & " And [Date Range]"
Between "#" & Me.[BeginDate] & "# And #" & Me.[EndDate] & "#"
DoCmd.OpenReport "Rep_workload", , , MyCondition
End Sub

But this doesn't work
ps: my form with the unbound boxes is called Date Range
 

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

Similar Threads


Top