report generated by comboboxes

J

Jorgen

Hi!

Thanks for all help up to this point!

I am still struggeling with having a form where one can specify to years in
a combo box, to get all entries which are in between. I have tried to sort by
date (given by a date() function) which works fine. But the field (year it
goes into production)i want to sort by, through to drop down boxes doesn't
work.

I have been wondering if it is because the field is defined as a text field,
but it should be possible to overcome!!

I have included the code under neath, so if someone wants to take a look, i
would be greatful! (Have gotten some good repiles from Allan Browne!!)

Private Sub Command4_Click()


Dim strreport As String
Dim strfield As String
Dim strwhere As String
Const conDateFormat = "#/yyyy\#"

strreport = "datesortreport"
strfield = "[main table].[Expected onstream year]"

If IsNull(Me.fromyear) Then
If Not IsNull(Me.toyear) Then
strwhere = strfield & " <= " & Format(Me.fromyear, conDateFormat)
End If
Else
If IsNull(Me.toyear) Then
strwhere = strfield & " >= " & Format(Me.toyear, conDateFormat)
Else
strwhere = strfield & " Between " & Format(Me.fromyear, conDateFormat) _
& " And " & Format(Me.toyear, conDateFormat)
End If
End If

DoCmd.OpenReport strreport, acViewPreview


End Sub
 
D

Duane Hookom

I never use the table name in my where clause (a report's record source
field names should all be unique).

Try something like:

Dim strreport As String
Dim strfield As String
Dim strwhere As String

strreport = "datesortreport"
strfield = "[main table].[Expected onstream year]"
strWhere = "1 = 1 "
If Not IsNull(Me.fromyear) Then
strwhere = " And Year([Expected onstream year]) >= " & Me.fromyear
End If
If Not IsNull(Me.toyear) Then
strwhere = strWhere & " And Year([Expected onstream year]) <= " &
Me.toyear
End If

DoCmd.OpenReport strreport, acViewPreview, , strWhere
 

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