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("Hello") 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 9812
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,556
Expert Mod 16PB
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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?
...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |