473,503 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find Field Data Type in VBA

bhcob1
19 New Member
I have a list which is populated with Fields from a table, I want to be able to determine if the data type of the value selected in the list is Number. Any ideas, i thought there would be something along the lines of

Me!lstQueryCriteria.Datatype, but my results turned up no dice.

The reason I wish to do this is, because I am creating a query in VBA and in the Where clause I use IN, and it is giving me a datatype mismatch whenever it is sent a Number data type.

The SQL statement created produces something along the lines of
IN('R10001','R10003')
But for a Number datatype
IN('1','3')
doesnot work, i need to remove the ' for this datatype
IN(1,3) and then it works

Excuse the babble, i think i have re-explained myself at least twice over.
Feb 13 '07 #1
3 36928
ADezii
8,834 Recognized Expert Expert
I have a list which is populated with Fields from a table, I want to be able to determine if the data type of the value selected in the list is Number. Any ideas, i thought there would be something along the lines of

Me!lstQueryCriteria.Datatype, but my results turned up no dice.

The reason I wish to do this is, because I am creating a query in VBA and in the Where clause I use IN, and it is giving me a datatype mismatch whenever it is sent a Number data type.

The SQL statement created produces something along the lines of
IN('R10001','R10003')
But for a Number datatype
IN('1','3')
doesnot work, i need to remove the ' for this datatype
IN(1,3) and then it works

Excuse the babble, i think i have re-explained myself at least twice over.
Here is a little Routine that will number all the Fields in a Table, list their Name, and if it is Numeric, list the Data Type. If not, N/A. Ideally, this could be refined and contained within a Function/Sub Procedure. You can adapt it to your own specifc needs, but if you further help just ask. The important point here is that the Type Property of a Field Object returns a Numeric Value indicating its Data Type.
Expand|Select|Wrap|Line Numbers
  1. Dim intNumberofFields As Integer, intFieldType As Integer, strTypeName As String
  2.  
  3. Dim fld As Field, intCounter As Integer, strFieldName As String
  4.  
  5. intNumberofFields = CurrentDb.TableDefs("tblEmployee").Fields.Count
  6.  
  7. For intCounter = 0 To intNumberofFields - 1
  8.   strFieldName = CurrentDb.TableDefs("tblEmployee").Fields(intCounter).Name
  9.   intFieldType = CurrentDb.TableDefs("tblEmployee").Fields(intCounter).Type
  10.     Select Case intFieldType
  11.       Case 2    'Byte
  12.         strTypeName = "Byte"
  13.       Case 3    'Integer
  14.         strTypeName = "Integer"
  15.       Case 4    'Long
  16.         strTypeName = "Long"
  17.       Case 6    'Single
  18.         strTypeName = "Single"
  19.       Case 7    'Double
  20.         strTypeName = "Double"
  21.       Case Else 'Not a Number
  22.         strTypeName = "N/A"
  23.     End Select
  24.      Debug.Print Format(intCounter + 1, "00") & ") " & strFieldName & " - " & strTypeName
  25. Next intCounter
Sample Output:
01) Counter - Long
02) PayrollNumber - Long
03) Order Date - N/A
04) Required_Date - N/A
05) Received_Date - N/A
06) Rank - N/A
07) LastName - N/A
08) FirstName - N/A
09) MI - N/A
10) Designation - N/A
11) MiscCode - N/A
12) Company - N/A
13) Platoon - N/A
14) VacationCode - N/A
15) Title - N/A
16) Address - N/A
17) ZipCode - N/A
18) Sex - N/A
19) BloodType - N/A
20) PhoneNumber - N/A
21) BirthDate - N/A
22) AppointmentDate - N/A
23) AssignmentDate - N/A
24) LongevityDate - N/A
25) Badge - N/A
26) SSN - N/A
27) DriverLicenseNumber - N/A
28) DriverLicExpDate - N/A
29) TransferredOut - N/A
30) Backup - N/A
31) FullName - N/A
32) Years - Integer
33) L - N/A
34) NoDays - Long
35) InvDate - N/A
36) EndDate - N/A
37) SSAN - N/A
38) Date - N/A
39) Integer - Integer
40) Long - Long
41) Single - Single
42) Double - Double
43) Byte - Byte
Feb 13 '07 #2
bhcob1
19 New Member
Thanks for that, very helpful
Feb 13 '07 #3
ADezii
8,834 Recognized Expert Expert
Thanks for that, very helpful
No Problemo.
Feb 13 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3252
by: Josh | last post by:
Hi, I am trying to write a function in a module in MS Access 2000 that will change the data type of a field called 'Start' in table 'bo_cpm_CS01ALL'. Here is the code that I have done so far...
1
2738
by: sleepyant | last post by:
Hi, how can I check the field data type of a column in a Dataset table? Like whether it is a DateTime, a Binary or Character. Please help. Thanks.
5
16896
by: chellappa | last post by:
Hi All, How to find the data type of the variable ? is there any libaray function avaiable? Because i want create generic data type of some operation . Thanks All By Chellappa
2
5457
by: comteck | last post by:
From one database, I am trying to create a table in a different database. Here is my code: Dim dbDeja As DAO.Database Dim tblEmployees As DAO.TableDef Dim fldEmployeeNumber As Field ...
0
1561
by: comteck | last post by:
From one database, I am trying to create a table in a different database. Here is my code: Dim dbDeja As DAO.Database Dim tblEmployees As DAO.TableDef Dim fldEmployeeNumber As Field ' Open...
2
2909
by: balaki | last post by:
Hi All, I am using VB.Net 2003 and Ms-Access 2003. I want to change the data type of fileds programmatically. I could not find any method in vb.net to do this. i) I tried using the sql query...
2
21763
by: fniles | last post by:
I am using VB.NET 2005 and SQLDataReader. How can I check the data type of a field in the DataReader ? Thank you. Dim cmdSQL As SqlClient.SqlCommand Dim drSQL As SqlClient.SqlDataReader sSQL...
0
1514
by: RN | last post by:
Hi everyone, First please let me explain. I am attempting to store pdf files in an MS Access DB (2000) and I have written a subroutine to do this. My code seems to work perfectly (see code...
7
1375
Shashi Sadasivan
by: Shashi Sadasivan | last post by:
Hi, i wanted to make a generec fntions which will compare a given object type against a lit of objects. my list of object are a set of forms, but sor simplicity lets assume it to be a lit of int,...
0
7313
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...
1
6970
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...
0
7441
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
5558
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,...
1
4987
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...
0
3156
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...
0
1489
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 ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
366
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...

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.