OpenArgs Timing

D

DS

I have a Control on a Report that gets a value from the OpenArgs statement.
Whenever I use the Open Arg to assign this value the following code doesn't
work.
If I however assign the value via the control source in the field such as =1
the code works.
Here is the Code

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.TxtOK = DLookup("SecurityID", "tblSecurityDetails", "SecurityID = " &
Me.TxtID & " And SDPrivID = PrivID")

If Me.TxtOK = Me.TxtID Then
Me.BoxYes.Visible = True
Me.BoxNo.Visible = False
Else
Me.BoxYes.Visible = False
Me.BoxNo.Visible = True
End If
End Sub

I have a feeling that it's a timing issue. Does the Format run before tthe
OpenArg? If so how can I remedy this situation?
Thanks
DS
 
D

DS

The OpenArgs is in the ControlSource of the TxtID field.
=Report.OpenArgs
I have it in the Detail Section, I also Tried the Page Header.
DS
 
D

DS

OK for what ever reason this seems to work. I kept all of the other code
and got rid of the if Statement.

Me.BoxYes.Visible = Not IsNull(Me.TxtOK)
Me.BoxNo.Visible = IsNull(Me.TxtOK)

Thanks
DS
 
F

fredg

The OpenArgs is in the ControlSource of the TxtID field.
=Report.OpenArgs
I have it in the Detail Section, I also Tried the Page Header.
DS

It would have been nice if you had included the previous message in
this reply. Without having it in front of me I have to keep going back
and forth. Notice how Duane included your message with his reply, as I
have yours with this reply. It's just a common courtesy to those who
read your message and wish to respond.

There is no reason why you can't refer to the OpenArgs directly in the
Report's Detail Format event. I would suspect, since you haven't shown
it even in your first post, that you have incorrectly referred to it.
Who knows?

The following code, in the report's Detail Format event, works for me:
Me![MyControlName] = Me.OpenArgs

Also, 'the following doesn't work' gives us absolutely no help in
identifying your problem.
Does the DLookup fail? Is the difficulty further down in your code in
the If .. Then section? What value do you get for txtOK? For txtID?
And what is SDPrivID? Is that supposed to be a field in your table
with a number datatype value? If so, why is the [PriID] not
concatenated into the DlookUp where clause ..... " and [SDPrivID] = "
& [PrivID])? That's assuming [PrivID] is a number. If it is a Text
datatype then it should be .... " and [SDPrivID = '" & [PrivID] & "'")

I would suggest you change the where clause as I suggest above, then
if you still have difficulty, place a break point in the format event,
step through the code line by line, and read the value of each control
by hovering the cursor over it for a moment. Then let us know if the
values are not what you think they should be.
 
D

DS

Sorry Fred.
I thought I was being nice by keeping it clean...In any case the part that
doesn't work is the if statement. The DLookup is fine. Also the TxtOK and
TxtID fields are number fields and they are being populated correctly.
TxtID is always a number and the TxtOK field is a number or it's NULL. This
all works if I hard code the TxtID field with a lets say =1 just for
arguments sake. However; when the value is being set from the form that
opens this report, this is when the if statement fails to execute. I only
see BoxNo. Never a BoxYes, even when it should be. So my guess is that the
OpenArgs is running after the Format Detail does. But if thats the case I
would get an Error on the DLookup? Correct? You did mention one thing. I
can run the OpenArgs directly from the Format_Detail? How would this be
done? Thank You for your help.
DS
 
D

DS

Ok Fred,
I tried the OpenArgs on the Format and it was a no go with the If statement.
It works when I replace the if statement with...

Me.BoxYes.Visible = Not IsNull(Me.TxtOK)
Me.BoxNo.Visible = IsNull(Me.TxtOK)

Like I said the values are there for TxtOK and TxtID.
Must be the if Statement, The first half doesn't work but the second part of
it does...always showing the BoxNo.

Thanks
DS
 

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