473,729 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing to optional variant

Here's the function:

Public Function SaveToServer(ta bleName 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("o bligation", "obl", Me!updated, Me.txtID)

It also does not work with:

success = SaveToServer("o bligation", "obl", Me!updated, Me!obligation_i d)

this works:

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

In the function, IsMissing(recor dID) 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
4 4105
-----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("t blPerson", "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/AwUBP7Apn4echKq OuFEgEQI70wCgo1 lw+UHqtwvGyJFFR OmiFlbERHkAnjjk
0PbVDiAQi0Ue/HtsL75DyNqU
=gBvr
-----END PGP SIGNATURE-----

Darryl Kerkeslager wrote:
Here's the function:

Public Function SaveToServer(ta bleName 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("o bligation", "obl", Me!updated, Me.txtID)

It also does not work with:

success = SaveToServer("o bligation", "obl", Me!updated, Me!obligation_i d)

this works:

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

In the function, IsMissing(recor dID) 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
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******** *********@newsr ead1.news.pas.e arthlink.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("t blPerson", "Mr.", #1/1/2003#,
CStr(Me!txtID))
Darryl Kerkeslager wrote:
Here's the function:

Public Function SaveToServer(ta bleName 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("o bligation", "obl", Me!updated, Me.txtID)

It also does not work with:

success = SaveToServer("o bligation", "obl", Me!updated, Me!obligation_i d)
this works:

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

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

Nov 12 '05 #3
-----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/AwUBP7CXeIechKq OuFEgEQKofwCglp g1R/igb5GI0J3vI8M4r IR8RgAAoIpE
SF9ygI14OXfzlZw TvSEL5+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******** *********@newsr ead1.news.pas.e arthlink.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("t blPerson", "Mr.", #1/1/2003#,
CStr(Me!txtID ))

< SNIP >

Nov 12 '05 #4
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("o bligation", "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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2145
by: spammy | last post by:
Hi all, Im attempting to use a COM class in C# via .NET interop. The class has two modes - synhrounous and asynchronous. The mode is determined by the use (or not) of an optional out parameter: COMClass test = new COMClass(); object results = null;
4
6183
by: Gerry Abbott | last post by:
Hi All, Im trying to use thie combination but have not had success. Below is the function It tried the following myriskLevel(2,2) myrisklevel(0,0,2) and the ismissing(Three) alwasy returns false.?
2
9588
by: Edlueze | last post by:
Greetings: I have two functions and I would like to pass the ParamArray gathered from one function to the other function. For the purposes of this post, let's say that they are calculating averages (they're actually processing a sequence of pairs of variants and the sequence is of unknown length). I want something like these two functions:
4
2673
by: MLH | last post by:
The following function declaration confuses me... Public Function IsEMailAddress(ByVal sEmail As String, Optional ByRef sReason As String) As Boolean I tried pasting it and its code into an Access 2.0 module. I was unsuccessful. I had to remove the following... "Public" "Optional ByRef" "As Boolean"
0
1642
by: lakshmi | last post by:
include the following lines of code: using System.Runtime.InteropServices; prefix the optional argument with This takes care if an optional parameter is not supplied by a VB script client. >-----Original Message----- >I found that optional parameters are not supported in C#. >We are currently rewriting a C++ dll in C#. The C++ dll
3
3792
by: Mark | last post by:
Hi From what I understand, you can pass arrays from classic ASP to .NET using interop, but you have to change the type of the.NET parameter to object. This seems to be because classic ASP passes a variant containing an array, and interop expects a parameter of type object if you are passing a variant (you are expected to cast it to the correct type in your code). I'd like to find a way of passing arrays so that you don't need to change...
7
2486
by: An Jiye | last post by:
Hi. I have an ActiveX control created by MFC. One method has the following definition: SHORT MyMethod(BSTR p1, VARIANT p2, VARIANT p3); In VB6, I can call this method by the following three ways:
13
2518
by: Deano | last post by:
Apparently you can only do this with one value i.e Call MyAssetLocationZoom(Me!txtLocation, "Amend data") This runs; Public Sub MyAssetLocationZoom(ctl As Control, formName As String) On Error GoTo err_zoom strFormName = formName
0
2022
by: dwinson | last post by:
I am writing an add-in in C# for a server written in VB6. In order for my add-in to work I need to implement this method: MyMethod(string inputData) .... so my C# code looks like this: public object MyMethod(string inputData)... I wrote a test harness in VB6 to test the method. I can call the method
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.