Filter with a parameter box appearing? (1 Viewer)

swarv

Registered User.
Local time
Today, 20:03
Joined
Dec 2, 2008
Messages
196
Hi all,

I have this:
Code:
Text2.SetFocus
Dim txtdept As String
Dim txtdept2 As String
txtdept = Text2.Text
txtdept2 = "dept=" + txtdept
DoCmd.OpenReport "Copy of inventory transactions - Choose Dept", acViewPreview, , txtdept2

but when I run it a enter parameter box appears asking for a dept. I dont want the box to appear because the value is already in text2.

Any ideas?

Thanks

Martin :confused:
 

NigelShaw

Registered User.
Local time
Today, 20:03
Joined
Jan 11, 2008
Messages
1,573
Hi Martin,

is the report linked to a query? If so, is there a criteria set on the query? Bear in mind that at the open report call, text2 value is for example-

Code:
Text2.SetFocus
Dim txtdept As String
Dim txtdept2 As String
txtdept = Text2.Text ' ( value is Accounts )
txtdept2 = "dept=" + txtdept
DoCmd.OpenReport "Copy of inventory transactions - Choose Dept", acViewPreview, , txtdept2

the value of text2 would be "dept=Accounts" so unless this is on the filed wher ethe report is opening to.........

also,

why set textdept2 with textdept? for arguments sakem you could simply use-
Code:
Dim txtdept As String

txtdept = "dept=" & Nz(Text2.Value, "")

DoCmd.OpenReport "Copy of inventory transactions - Choose Dept", acViewPreview, , txtdept

Cheers

Nidge
 

swarv

Registered User.
Local time
Today, 20:03
Joined
Dec 2, 2008
Messages
196
sorted. I forgot the ' 's.

thanks
 

swarv

Registered User.
Local time
Today, 20:03
Joined
Dec 2, 2008
Messages
196
also I must look up the Nz bit. Not sure what it means yet. I'll try that aswell. Thanks for this
 

NigelShaw

Registered User.
Local time
Today, 20:03
Joined
Jan 11, 2008
Messages
1,573
also I must look up the Nz bit. Not sure what it means yet. I'll try that aswell. Thanks for this

Hi,

Nz = Null to Zero

If the return value is Null or 0 or "" depending on var type, you can declare a return value. Good when you get issue for no record-

Code:
Dim iTest As Integer
Dim sTest As String
 
iTest = Nz(MyForm!txtTestNum, 0)
sTest = Nz(MyForm!txtTestText , "")
 
If iTest = 0 Then
  Exit Sub
  Else
  If sTest = "" Then
    Exit Sub
    Else
    'do Something
  End If
End If

in my example, it the field references return no value, then the Nz places a value to the variable.


hope that helps


nidge
 

swarv

Registered User.
Local time
Today, 20:03
Joined
Dec 2, 2008
Messages
196
now that will come in use. I never knew that. thanks
 

Users who are viewing this thread

Top Bottom