By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,659 Members | 910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,659 IT Pros & Developers. It's quick & easy.

Passing to optional variant

P: n/a
Here's the function:

Public Function SaveToServer(tableName As String, prefix As String, _
changed As Date, Optional
recordID As Variant)
As Boolean

and here's the function call that doesn't work:

success = SaveToServer("obligation", "obl", Me!updated, Me.txtID)

It also does not work with:

success = SaveToServer("obligation", "obl", Me!updated, Me!obligation_id)

this works:

Dim id as Long
id = Me.txtID
success = SaveToServer("obligation", "obl", Me!updated, id)

In the function, IsMissing(recordID) acts as it should, but any other call
to recordID
errs out with the first tow calls.

What the ...?
Darryl Kerkeslager


Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

My guess is the "recordID" parameter is getting a reference to the
control object instead of to the control's value. Therefore, you
should explicitly set the data type of the variant when you pass the
parameter to the function. E.g.:

blnResult = SaveToServer("tblPerson", "Mr.", #1/1/2003#,
CStr(Me!txtID))

MGFoster:::mgf
Oakland, CA (USA)
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP7Apn4echKqOuFEgEQI70wCgo1lw+UHqtwvGyJFFROmiFl bERHkAnjjk
0PbVDiAQi0Ue/HtsL75DyNqU
=gBvr
-----END PGP SIGNATURE-----

Darryl Kerkeslager wrote:
Here's the function:

Public Function SaveToServer(tableName As String, prefix As String, _
changed As Date, Optional
recordID As Variant)
As Boolean

and here's the function call that doesn't work:

success = SaveToServer("obligation", "obl", Me!updated, Me.txtID)

It also does not work with:

success = SaveToServer("obligation", "obl", Me!updated, Me!obligation_id)

this works:

Dim id as Long
id = Me.txtID
success = SaveToServer("obligation", "obl", Me!updated, id)

In the function, IsMissing(recordID) acts as it should, but any other call
to recordID
errs out with the first tow calls.

What the ...?
Darryl Kerkeslager


Nov 12 '05 #2

P: n/a
First, it works like you said. But what is the answer behind the answer?
The error I was getting was 2424, "The expression you entered has a field,
control, or property name that [app] can't find". I searched the newsgroup
thoroughly, and found that a number of people had encountered the error -
most with menus and command bars. The solutions that existed seemed to
center on bound controls that were not connected to the proper field name.
I checked this out; it didn't apply.

Your 'guess' was right on the money ... but why/how could this happen? I
shouldn't have to do this workaround. I never have before ... so what could
be different here?

Thanks again

Darryl
"MGFoster" <me@privacy.com> wrote in message
news:DQ*****************@newsread1.news.pas.earthl ink.net...

My guess is the "recordID" parameter is getting a reference to the
control object instead of to the control's value. Therefore, you
should explicitly set the data type of the variant when you pass the
parameter to the function. E.g.:

blnResult = SaveToServer("tblPerson", "Mr.", #1/1/2003#,
CStr(Me!txtID))
Darryl Kerkeslager wrote:
Here's the function:

Public Function SaveToServer(tableName As String, prefix As String, _
changed As Date, _
Optional recordID As Variant) As Boolean

and here's the function call that doesn't work:

success = SaveToServer("obligation", "obl", Me!updated, Me.txtID)

It also does not work with:

success = SaveToServer("obligation", "obl", Me!updated, Me!obligation_id)
this works:

Dim id as Long
id = Me.txtID
success = SaveToServer("obligation", "obl", Me!updated, id)

In the function, IsMissing(recordID) acts as it should, but any other call to recordID errs out with the first tow calls.

Nov 12 '05 #3

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Again a guess, if a parameter is a ByRef (the default) Variant it will
take the "biggest" object. Since the Control was used as the calling
parameter the called procedure used the Control 'cuz it was the
biggest (most general) item it could evaluate from the passed
reference.

My guess: If the Optional parameter was typed as a string, then the
value stored in the Control would be used because a string isn't a
Control.

HTH,

MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP7CXeIechKqOuFEgEQKofwCglpg1R/igb5GI0J3vI8M4rIR8RgAAoIpE
SF9ygI14OXfzlZwTvSEL5+yy
=kvlo
-----END PGP SIGNATURE-----

Darryl Kerkeslager wrote:
First, it works like you said. But what is the answer behind the answer?
The error I was getting was 2424, "The expression you entered has a field,
control, or property name that [app] can't find". I searched the newsgroup
thoroughly, and found that a number of people had encountered the error -
most with menus and command bars. The solutions that existed seemed to
center on bound controls that were not connected to the proper field name.
I checked this out; it didn't apply.

Your 'guess' was right on the money ... but why/how could this happen? I
shouldn't have to do this workaround. I never have before ... so what could
be different here?

Thanks again

Darryl
"MGFoster" <me@privacy.com> wrote in message
news:DQ*****************@newsread1.news.pas.earthl ink.net...
My guess is the "recordID" parameter is getting a reference to the
control object instead of to the control's value. Therefore, you
should explicitly set the data type of the variant when you pass the
parameter to the function. E.g.:

blnResult = SaveToServer("tblPerson", "Mr.", #1/1/2003#,
CStr(Me!txtID))

< SNIP >

Nov 12 '05 #4

P: n/a
I don't know how long it would have taken me to figure this out.

Based on what you told me, I thought that this should work:

blnResult = SaveToServer("obligation", "obl", #1/1/2003#,
Me.txtID.value)

(added the .value property) and it did.

When I started programming in Access, I used the .value property all the
time, because I was thought that it would slow things down if I didn't.
After testing and finding no such result, I stopped using it - but now I
have a reason to use it, and I will from now on.

Darryl Kerkeslager
Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.