Help!!!!. Code is not working correctly

A

Ayo

Could anyone help me out with these codes. Something is wrong but I can't
figure it out.
This particular line of code is suppose to have 3 OpenArgs for the form
"Invoice by Dates" but only the first two gets included. Me.cmbReviewer.Value
is not included
DoCmd.OpenForm "Invoice by Dates", acNormal, acWindowNormal,
OpenArgs:=Me.txtStartDate.Value & "," & Me.txtEndDate.Value & "," & "," &
Me.cmbReviewer.Value

This snippet of code is suppose to tell me where the first comma, the 2nd
comma and the 3rd comma are in the OpenArgs. I am not sure if I am writing it
correctly.
If IsNull(Me.OpenArgs) = False Then
commaOne = InStr(Me.OpenArgs, ",")
commaTwo = InStr(Mid(Me.OpenArgs, commaOne + 1), ",")
commaThree = InStr(Mid(Me.OpenArgs, commaTwo + 1), ",")
Else
'------ Insert Exit sub here with Msgbox ----------------'
End If

Any help will be greatly appreciated. Thank you.
 
A

Ayo

Yes. There are 4 scnerios. And I need all the args to be in the same
positions depending one if which I am using.

DoCmd.OpenForm "Invoice by Dates", acNormal, acWindowNormal,
OpenArgs:=Me.txtStartDate.Value & "," & Me.txtEndDate.Value

DoCmd.OpenForm "Invoice by Dates", acNormal, acWindowNormal,
OpenArgs:=Me.txtStartDate.Value & "," & Me.txtEndDate.Value & "," &
Me.cmbVendor.Value & "," & Me.cmbReviewer

DoCmd.OpenForm "Invoice by Dates", acNormal, acWindowNormal,
OpenArgs:=Me.txtStartDate.Value & "," & Me.txtEndDate.Value & "," &
Me.cmbVendor.Value

DoCmd.OpenForm "Invoice by Dates", acNormal, acWindowNormal,
OpenArgs:=Me.txtStartDate.Value & "," & Me.txtEndDate.Value & "," & "," &
Me.cmbReviewer.Value
 
T

Tom van Stiphout

As long as you realize that, your code is OK. THe debugger can confirm
this.
Personally I don't do it this way. Rather I create a querystring-like
string:
OpenArgs:="StartDate=" & Me.txtStartDate.Value & "&EndDate=" &
Me.txtEndDate.Value etc.
Then I write the code once to parse such string into a dictionary
object, and use it for all my forms and all my projects. I like the
fact that the string becomes self-describing and I haven't had a
parsing error in years (last time was with embedded & characters,
which I solved the same way as on the web: urlencode/decode).

-Tom.
 
A

Ayo

Thanks Tom. But how do I use them when I hope the other.
form.OpenArgs:="StartDate=" & Me.txtStartDate.Value & "&EndDate=" &
Me.txtEndDate.Value etc.
For example in the form_load event I you suggesting that I use this:
Private Sub Form_Load()
Me.txtStartDate.Value = StartDate
Me.txtSEndDate.Value = EndDate
 
A

Ayo

Is there an exmple you can show me on how to do this dictionary object. I
have never used it before and reading the description in the help file, I am
still not sure how it would work for me or how to go about ctreating it for
my particular situation.
 
T

Tom van Stiphout

A dictionary object is a collection of name/value pairs, just like a
querystring is.
You can turn the querystring into a dictionary object by using the
Split function to split on "&", and then within each element use the
Split function again to split on "=".
You'll need to read up on the Scripting.Dictionary object to find out
how to use it. I see it as an array on steroids: you can add
name/value pairs (.Add), you can test for existence (.Exists), and of
course get the value of a particular element (.Value).

To apply this to your situation: once you have the dictionary object
there is no more need to find the commas. Rather you would write code
like this:
dim dtStartDate as Date
dtStartDate = dict("StartDate").Value

if dict.Exists("Vendor") then
intVendorID = dict("Vendor")

-Tom.
 

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