473,471 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Can you tell the datatype of a control

SJM
Howdy,
I have a form with a number of different text box controls on it displaying
data for a relevant record that the user has selected. I want to run a
filter/search function that runs off the control that the user has last
clicked on. I have already built it and it works well in most circumstances
but not 100%. For it to be bullet proof I need to be able to determine the
data type of the field the user has clicked on. While I can look at the
first character to see if it is alpha or numeric, this does not work in all
cases, especially when dealing with say product codes for instance. Is there
a way using VBA to determine what the data type of a form control is?
Nov 13 '05 #1
2 5950
Look at the ControlSource to get the name of the field it is bound to.

Then examine the Type of the field in the RecordsetClone of the form.
You'll need error checking, but this is the basic idea:
strField = Form.ActiveControl.ControlSource
Debug.Print Me.RecordsetClone.Fields(strField).Type

The function below converts the DataTypeEnum value to English:

Function FieldTypeName(n As Long) As String
'Purpose: Converts the numeric results of DAO fieldtype to text.
'Note: fld.Type is Integer, but the constants are Long.
Dim strReturn As String 'Name to return

Select Case n
Case dbBoolean: strReturn = "Yes/No" '1
Case dbByte: strReturn = "Byte" '2
Case dbInteger: strReturn = "Integer" '3
Case dbLong: strReturn = "Long Integer" '4
Case dbCurrency: strReturn = "Currency" '5
Case dbSingle: strReturn = "Single" '6
Case dbDouble: strReturn = "Double" '7
Case dbDate: strReturn = "Date/Time" '8
Case dbBinary: strReturn = "Binary" '9
Case dbText: strReturn = "Text" '10
Case dbLongBinary: strReturn = "OLE Object" '11
Case dbMemo: strReturn = "Memo" '12
Case dbGUID: strReturn = "GUID" '15
Case dbBigInt: strReturn = "Big Integer" '16
Case dbVarBinary: strReturn = "VarBinary" '17
Case dbChar: strReturn = "Char" '18
Case dbNumeric: strReturn = "Numeric" '19
Case dbDecimal: strReturn = "Decimal" '20
Case dbFloat: strReturn = dbFloat '21
Case dbTime: strReturn = "Time" '22
Case dbTimeStamp: strReturn = "Time Stamp" '23
Case Else: strReturn = "Field type " & n & "unknown"
End Select

FieldTypeName = strReturn
End Function
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"SJM" <ak*****@ozemail.com.au> wrote in message
news:ZR****************@nnrp1.ozemail.com.au...
Howdy,
I have a form with a number of different text box controls on it
displaying
data for a relevant record that the user has selected. I want to run a
filter/search function that runs off the control that the user has last
clicked on. I have already built it and it works well in most
circumstances
but not 100%. For it to be bullet proof I need to be able to determine the
data type of the field the user has clicked on. While I can look at the
first character to see if it is alpha or numeric, this does not work in
all
cases, especially when dealing with say product codes for instance. Is
there
a way using VBA to determine what the data type of a form control is?

Nov 13 '05 #2
SJM
Thanks Allen for speedy response
Wont test it out till tomorrow but it looks like it will solve my dilemma
Neat!

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Meredith | last post by:
Question: Can the XML <any> element restrict what datatype it stores? I am trying to write an extensible schema that has an element containing unbounded <any> elements of boolean type. Is it...
8
by: Eternally | last post by:
Hi folks, I've got a program which has a function which uses templates to accept parameters of any type. Works well, but there's one certain datatype which I want to special case and do an...
1
by: Chris Uwins | last post by:
Hi there, i know theres a number of ways I can achieve this but want to know the best, (but still quite simple). Up until a year ago I never used Access but have designed a few databases for...
1
by: Zack Sessions | last post by:
I am trying to implement a ListBox control in VB.NET. I am using the sample code right from the online help, but I am stuck on simply declaring a list item variable. The datatype ListItem simply...
1
by: Rich | last post by:
Hello, I have been adding a handler to the TextBox.Leave event to check if a value that is entered in a Date Textbox is a Date. This works OK. But I am just checking if there is anything...
4
by: Orchid | last post by:
How can I change a Date datatype to a Number datatype? For example, I want a date 10/31/2006 to show 1031 as Number datatype. But I don't want it becomes 39021. What formula should I use? ...
1
by: ChrisFrohlich | last post by:
ASP.NET 2.0 with Text DataTypes: I've got a similar question going in the SQL group, but I was wondering if anyone has successfully implemented reading/writing character data from a Text datatype...
10
by: Nathan Sokalski | last post by:
I am using ASP.NET 2.0, and need to know how to save and use an image that is stored in an SQL Server image datatype. How can I do this using ASP.NET? Thanks.
2
by: shahalashamo | last post by:
in order to upload image to database,i put a fileUpload control in the InsertItemTemplate of the formView,the code as follows: <asp:FileUpload ID="FileUploadKeyImage"...
0
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...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
tracyyun
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...
0
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,...
0
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...
0
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...

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.