Code Problem, please help.

  • Thread starter Thread starter Stockwell43
  • Start date Start date
S

Stockwell43

Hello,

I have a form that I type in the data and in the dteail report field made a
copy of the fields from the report. What I want is for the information I
typed in the fields of the form to show on the report when I click the button.

Here is the code behind the button:

Private Sub cmdRunReport_Click()


If Len(Me.Title & "") > 0 Then
strWhere = strWhere & " AND textfield LIKE " & Me.Title & "*"
End If

If Len(Me.DiscType & "") > 0 Then
strWhere = strWhere & " AND textfield LIKE " & Me.DiscType & "*"
End If

If Len(Me.CDCatagory & "") > 0 Then
strWhere = strWhere & " AND textfield LIKE " & Me.CDCatagory & "*"
End If

If Len(Me.CDArtist & "") > 0 Then
strWhere = strWhere & " AND textfield LIKE " & Me.CDArtist & "*"
End If

If Len(Me.DVDCatagory & "") > 0 Then
strWhere = strWhere & " AND textfield LIKE " & Me.DVDCatagory & "*"
End If

If Len(Me.DVDActors & "") > 0 Then
strWhere = strWhere & " AND textfield LIKE " & Me.DVDActors & "*"
End If

****Dim strWhere As String 'String variable to store where clause

If Len(strWhere & "") = 0 Then
' no options selected. Open report with no where condition
DoCmd.OpenReport "rptinventory", acViewPreview
Else
' remove first "AND" from where condition and pass across to report
DoCmd.OpenReport "rptinventory", acViewPreview,
WhereCondition:=Mid(strWhere, 6)
End If


End Sub

The code stops where I placed the **** (not in the code just making it
easier for you to find) and an error comes up saying:

"Duplicate declaration in current scope"

Does anyone know how to fix this? I got it from a site.

Thanks!
 
hi Dean,
The code stops where I placed the **** (not in the code just making it
easier for you to find) and an error comes up saying:

"Duplicate declaration in current scope"

Does anyone know how to fix this? I got it from a site.
In VBA you can declare variables implicit by using it. This is the
default behaviour, which has also major draw back, consider this code:

strTest = "Test;
strText = strTest + "!"
MsgBox strTest

First of all: In the VBA IDE, set the option under Tools\Options\Editor
- Require Variable Declaration. This will enforce the explicit
declaraction of variables before their first use. This option will
autmatically insert an

Option Explicit

in the module header. As your module already exists, place it there
manually.

Then move your declaration statement at the begin of your procedure.


mfG
--> stefan <--
 
Back
Top