473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 5923
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.