i've got a brainteaser for you guys. let's say i have a form called "Form1"...
now, i have a lot of fields on Form1 and get tired of typing out forms!form1. fillintheblank.value because they are referenced quite a bit. so i want to create a function that will fill in the blank and return the value that resides in that location. the problem is, once it is converted to string (in order to use concatenation) i can't seem to convert it back to a true variant. it always retains the form of a string. take this for example: - Function Permissions(Root As String)
-
Dim strRoot As String
-
Dim varRoot As Variant
-
strRoot = "[Forms]![Form1].[" & Root & "].value"
-
varRoot = (CVar(strRoot)
-
If CurrentProject.AllForms("Form1").IsLoaded Then
-
Permissions = Nz(varRoot, 0)
-
Else: Permissions = 0
-
End If
-
Debug.Print Permissions
-
End Function
the output of Permissions("He llo") is:
[Forms]![Form1].[Hello].value
i would much rather have the output be whatever value is in that field :)
is there any possible way around this? i've thrown the kitchen sink at this problem and i've got nothing. any suggestions? thanks guys.
--nate
6 9863 ADezii 8,834
Recognized Expert Expert
This is absolutely no need to always use the Fully Qualified Reference for a Form Field, use the Shortcut Version: - 'to refer to the [txtLastName] Field on Form1
-
Dim frm As Form
-
-
Set frm = Forms![Form1]
-
Debug.Print frm![txtLastName]
This is absolutely no need to always use the Fully Qualified Reference for a Form Field, use the Shortcut Version: - 'to refer to the [txtLastName] Field on Form1
-
Dim frm As Form
-
-
Set frm = Forms![Form1]
-
Debug.Print frm![txtLastName]
i'm not sure what that does for me. i added this to my code it still returned the value as a string--not the value in the form: - Function Permissions(Root As Variant)
-
Dim strRoot As String
-
Dim varRoot As Variant
-
Dim CvarRoot As Variant
-
Dim frm As Form
-
-
'to refer to frm!Root as defined in function
-
Set frm = Forms![Form1]
-
strRoot = "frm!" & Root
-
CvarRoot = CVar(strRoot)
-
varRoot = CvarRoot
-
-
If CurrentProject.AllForms("Form1").IsLoaded Then
-
Permissions1 = Nz(varRoot, 0)
-
Else: Permissions = 0
-
End If
-
Debug.Print Permissions
-
End Function
somehow i need to concatenate 2 variants--WITHOUT converting it to a string. and i have no idea if this is possible or how it would be done.
Hi Nate. I think there is some confusion over what you are trying to achieve; if you want to return the value of a control you don't need the various variable assignments in your function, and as ADezii has pointed out you can refer to a field directly.
There are several ways to do so. I use the following general function, supplying as arguments the name of the form and the name of the field whose value is to be returned as strings in each case: - Public Function FormFieldValue(FormName As String, FieldName As String)
-
FormFieldValue = Forms(FormName).Controls(FieldName)
-
End Function
The function is untyped (it returns a variant value).
I use this function in complex Access queries to replace direct form field references, which the Jet Database Engine often cannot recognise.
-Stewart
NeoPa 32,579
Recognized Expert Moderator MVP
For controls within the current form, called from within the form's module, you need even less.
For clarity, most use Me. in front of control references, but that, and the .Value, are actually defaulted anyway, so a reference to Me.ControlName. Value, can actually be expressed in the code simply as ControlName.
For controls within the current form, called from within the form's module, you need even less.
For clarity, most use Me. in front of control references, but that, and the .Value, are actually defaulted anyway, so a reference to Me.ControlName. Value, can actually be expressed in the code simply as ControlName.
alright, i didn't know that. that is good to know. thanks, NeoPa
Hi Nate. I think there is some confusion over what you are trying to achieve; if you want to return the value of a control you don't need the various variable assignments in your function, and as ADezii has pointed out you can refer to a field directly.
There are several ways to do so. I use the following general function, supplying as arguments the name of the form and the name of the field whose value is to be returned as strings in each case: - Public Function FormFieldValue(FormName As String, FieldName As String)
-
FormFieldValue = Forms(FormName).Controls(FieldName)
-
End Function
The function is untyped (it returns a variant value).
I use this function in complex Access queries to replace direct form field references, which the Jet Database Engine often cannot recognise.
-Stewart
PERFECT! yes, that is exactly what i was trying to achieve. sorry for explaining it so poorly. i will try this out but i'm sure it will work. thank you so much!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: DanSteph |
last post by:
hello all,
I have a problem, I have a DOUBLE value like that
4065 4000 0000 0000
and I want to convert it to a DWORD like that:
4065 4000
if I do result=(DWORD)MyDouble it end with AA(170)
|
by: Norvin Laudon |
last post by:
Hi,
Can somebody explain the following, from the MSDN documentation for the
"System.Convert.ToInt32(double)" function
<quote>
Return Value
value rounded to the nearest 32-bit signed integer. If value is halfway
between two whole numbers, the even number is returned; that is, 4.5 is
|
by: David Scemama |
last post by:
Hi,
I'm writing a program using VB.NET that needs to communicate with a DOS
Pascal program than cannot be modified. The communication channel is through
some file databases, and I have a huge problem writing VB Double values to
the file so as the Pascal program can read them as Pascal Real values.
I've managed to find the algorithm to read the Pascal Real format and
convert it to a VB Double, but I cannot figure out the opposite...
|
by: PeterK |
last post by:
I am trying to set Public overridable CreditlimitS() as
System.Data.SqlTypes.SqlMoney to Creditlimit as Double
like CreditLimitS=creditlimit
and get this error "Value of type double cannot be converted to
System.Data.SqlTypes.SqlMoney "
How do I get creditlimit into creditlimitS?
There seems to be no conversion function.
TIA
|
by: Doug |
last post by:
Hi
I have a short piece of trial code that compares some input and then
produces a message based on the value.
However I get a build error that i dont know how to resolve ' Cannot
implicitly convert type 'double' to 'bool'
The code is
| |
by: Edwin Knoppert |
last post by:
In my code i use the text from a textbox and convert it to a double value.
I was using Convert.ToDouble() but i'm used to convert comma to dot.
This way i can assure the text is correct.
However it seems this convert is determined by the local settings and comma
is indeed used as decimal separator.
Is there another way to convert a dotted value to a double variable?
Like 1234.5 and not 1234,5
|
by: michael mazanek |
last post by:
Hi all,
i have a VARIANT variable which contains a "friendly name" of a
video-codec (direct show).
Does anyone know how to retrieve the friendly name as a string to
display it on the console?
Thanks for any advice!
mm
|
by: ElizaInternet |
last post by:
I need convert NITF Xmls for insert into BD SQL. I try convert to file text and then insert into BD
I used the Syndication:NITF of perl for this convertion.
Any have information about this??, I can´t convert all tags and export to file text.
Somebody knows another form to do it???
thanks for help
|
by: rhyme2ri2 |
last post by:
Hello all,
how can i convert a variant data type into image. Actually i am retrieving an image from CCD (camera) which is in variant format. Now i want to display this image in picture/image box.(that is what i thought cud b one way ; feel free to suggest some other way of displaying my image). How can i convert this variant type to image.
Any help wud b appreciated
Thanks & Regards
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
| |
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...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |