views:

34

answers:

1

I have a simple piece of code written to open a report.

  Private Sub FormButton_Enter()
    Dim strwhere As String
    strwhere = Me.FormText
    DoCmd.Openreport "rtpname",acViewPreview,,"ColumnName=" & strwhere 
  End Sub

I am getting two popups , even though i pass the filter criteria from the form. Please advice.

+1  A: 

One potential cause is that ColumnName is non-numeric and you are not putting the value in quotes. If this the problem then the fix is:

 DoCmd.Openreport "rtpname",acViewPreview,,"ColumnName='" & strwhere & "'"
BenV
Works like charm. Thank you.
misguided
@misguided: Glad it worked. Please accept this answer by clicking the checkmark on the left.
BenV
I can't quite figure out why this answer works. Leaving out quotes for a text field shouldn't result in a parameter prompt, just a data type mismatch.
David-W-Fenton
@Fenton: Because it interpreted the value as an expression that it expected to refer either to a field on an open form or a column in the query behind "rptname". Since it couldn't evaluate that expression, it prompted for a value for it, and then it prompted for a value for the original "ColumnName".
BenV