code problem

M

Martin

Who can help me with the following problem in Access 2000:

I've got a button in a form to open a report. In this report I only want
some sorted information. To sort I select first in a combobox
(cboProjectverslag), next to the button.
The code under the button is pasted below.

With this code I'm not able to make the report work. I've tried everything,
but nothing works. So I guess the code is wrong!

Who can help?
Thanks,
Martin


'===start code:
Private Sub AfdrVBRapp_Click()
On Error GoTo Err_AfdrVBRapp_Click

Dim stDocName As String
Dim strSQL As String
If Len(Me!cboProjectVerslag) Then
strSQL = "SELECT * FROM [qryOverzicht] " & _
"WHERE [UitvrId]=" & Me!cboProjectVerslag
Else
strSQL = "SELECT * FROM [qryOverzicht]"
End If
stDocName = "rpBesprVerslag"
DoCmd.OpenReport stDocName, acPreview
.RecordSource = strSQL
.Form.Requery
End With
'=== eind code
 
J

Jonathan

-----Original Message-----
Who can help me with the following problem in Access 2000:

I've got a button in a form to open a report. In this report I only want
some sorted information. To sort I select first in a combobox
(cboProjectverslag), next to the button.
The code under the button is pasted below.

With this code I'm not able to make the report work. I've tried everything,
but nothing works. So I guess the code is wrong!

Who can help?
Thanks,
Martin


'===start code:
Private Sub AfdrVBRapp_Click()
On Error GoTo Err_AfdrVBRapp_Click

Dim stDocName As String
Dim strSQL As String
If Len(Me!cboProjectVerslag) Then
strSQL = "SELECT * FROM [qryOverzicht] " & _
"WHERE [UitvrId]=" & Me!cboProjectVerslag
Else
strSQL = "SELECT * FROM [qryOverzicht]"
End If
stDocName = "rpBesprVerslag"
DoCmd.OpenReport stDocName, acPreview
.RecordSource = strSQL
.Form.Requery
End With
'=== eind code
Hi Martin,

Reports have an orderby property. use online help for an
example. Basically it is a string without the words order
by, that lists the fields.

Luck
Jonathan
 
M

Martin

Thanks for your answer, but I don't think I can do anything with it. Are you
saying that I have to make adjustments in the report itself, and that the
code is okay?

Please specify,
Thanks,
Martin


"> Hi Martin,
 
S

SteveS

Martin,

Try this:

Open the report "rpBesprVerslag" in design view and set
the RecordSource to the query "qryOverzicht".


Change the code for the button(??)to:

Private Sub AfdrVBRapp_Click()
' if there is no error code, delete the next line
On Error GoTo Err_AfdrVBRapp_Click

Dim stDocName As String
Dim strWhere As String

If Len(Me!cboProjectVerslag) > 0 Then '<< Zero not Oh
' Where clause without the word "Where"
strWhere = " [UitvrId]=" & Me!cboProjectVerslag
End If

stDocName = "rpBesprVerslag"
DoCmd.OpenReport stDocName, acPreview,,strWhere
' two commas ^^
End Sub
'=== eind code

I couldn't find and .Requery for reports like you were
trying to use.

HTH

Steve
 
M

Martin

That's it! Thanks,
Martin

SteveS said:
Martin,

Try this:

Open the report "rpBesprVerslag" in design view and set
the RecordSource to the query "qryOverzicht".


Change the code for the button(??)to:

Private Sub AfdrVBRapp_Click()
' if there is no error code, delete the next line
On Error GoTo Err_AfdrVBRapp_Click

Dim stDocName As String
Dim strWhere As String

If Len(Me!cboProjectVerslag) > 0 Then '<< Zero not Oh
' Where clause without the word "Where"
strWhere = " [UitvrId]=" & Me!cboProjectVerslag
End If

stDocName = "rpBesprVerslag"
DoCmd.OpenReport stDocName, acPreview,,strWhere
' two commas ^^
End Sub
'=== eind code

I couldn't find and .Requery for reports like you were
trying to use.

HTH

Steve
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)

-----Original Message-----
Who can help me with the following problem in Access 2000:

I've got a button in a form to open a report. In this report I only want
some sorted information. To sort I select first in a combobox
(cboProjectverslag), next to the button.
The code under the button is pasted below.

With this code I'm not able to make the report work. I've tried everything,
but nothing works. So I guess the code is wrong!

Who can help?
Thanks,
Martin


'===start code:
Private Sub AfdrVBRapp_Click()
On Error GoTo Err_AfdrVBRapp_Click

Dim stDocName As String
Dim strSQL As String
If Len(Me!cboProjectVerslag) Then
strSQL = "SELECT * FROM [qryOverzicht] " & _
"WHERE [UitvrId]=" & Me!cboProjectVerslag
Else
strSQL = "SELECT * FROM [qryOverzicht]"
End If
stDocName = "rpBesprVerslag"
DoCmd.OpenReport stDocName, acPreview
.RecordSource = strSQL
.Form.Requery
End With
'=== eind code


.
 

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