The code:
Debug.Print RS.Fields(K).Type
return a numeric value to identify the type of filed.
possible to get the type value, similar, string, numeri, date, ecc...
i have see in google, for each numeric value, exists a table in clear
GET type of fields
-
- Administrator
- Posts: 12615
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
-
- Administrator
- Posts: 78535
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: GET type of fields
See DataTypeEnum for a list of field types. You will need only a few of them.
You could use code like this:
You could use code like this:
Code: Select all
Dim strFieldType As String
Select Case RS.Fields(K).Type
Case adBoolean
strFieldType = "Boolean"
Case adCurrency
strFieldType = "Currency"
Case adDate
strFieldType = "Date"
Case adDouble
strFieldType = "Double"
Case adInteger
strFieldType = "Long Integer"
Case adSingle
strFieldType = "Single"
Case adSmallInt
strFieldType = "Integer"
Case adVarChar
strFieldType = "Text"
Case Else
strFieldType = "Other Field Type"
End Select
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: GET type of fields
I had thought too but 34 enum in select case ...HansV wrote: ↑02 Oct 2022, 21:43See DataTypeEnum for a list of field types. You will need only a few of them.
You could use code like this:
Code: Select all
Dim strFieldType As String Select Case RS.Fields(K).Type Case adBoolean strFieldType = "Boolean" Case adCurrency strFieldType = "Currency" Case adDate strFieldType = "Date" Case adDouble strFieldType = "Double" Case adInteger strFieldType = "Long Integer" Case adSingle strFieldType = "Single" Case adSmallInt strFieldType = "Integer" Case adVarChar strFieldType = "Text" Case Else strFieldType = "Other Field Type" End Select
if is the only way, ok.
-
- Administrator
- Posts: 78535
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: GET type of fields
You probably never use most of the field types - only some of them apply to a Microsoft Access database. The code that I posted will probably be sufficient.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
-
- 4StarLounger
- Posts: 562
- Joined: 27 Jun 2021, 10:46
Re: GET type of fields
If only there were a way to list enums by name and value ... and, if you are working from Vb6 as I believe you are, there is! But it is a bit advanced and may in the end be more effort than the Case statement.
Happy to post though, if you are interested, sal21
Happy to post though, if you are interested, sal21
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: GET type of fields
YES, i'm interested, if you want
-
- 4StarLounger
- Posts: 562
- Joined: 27 Jun 2021, 10:46
Re: GET type of fields
OK. You need a form with a textbox set to multiline (and with a vertical scrollbar enabled, preferably). You will also need to add a reference to the Typelib Information library. Then:
Code: Select all
Option Explicit
' Requires a multiline textbox (preferably with vertical scrollbar enabled)
Private Sub Form_Load()
Text1.Text = GetADOEnumMemberName("DataTypeEnum")
End Sub
' Requires a reference to Typelib Information to be added to the project. If distributing your executable, make sure it is packaged with this library.
' This example is hardcoded to look at ADO enums, but with appropriate parameter passed to TLI.TypeLibInfoFromFile can work with any ActiveX library
Public Function GetADOEnumMemberName(strEnumName As String, Optional varVal As Variant) As Variant
Dim TLIApp As TLIApplication
Dim myConstant As ConstantInfo
Dim EnumMember As MemberInfo
Dim ADOTLI As TypeLibInfo
Set TLIApp = New TLIApplication
' Get our type library info from the relevant file
' This is the line that makes this example specific to the ADO object library
Set ADOTLI = TLI.TypeLibInfoFromFile("c:\program files\common files\system\ado\msado15.dll")
' Loop through members of libraries constants
For Each myConstant In ADOTLI.Constants
If myConstant.TypeKind = TKIND_ENUM And myConstant.Name = strEnumName Then
For Each EnumMember In myConstant.Members
If Not IsMissing(varVal) Then
Select Case TypeName(varVal)
Case "String"
If EnumMember.Name = varVal Then GetADOEnumMemberName = EnumMember.Value
Case "Integer"
If EnumMember.Value = varVal Then GetADOEnumMemberName = EnumMember.Name
End Select
Else
' List all members of this enum in debug window if you like
' Debug.Print EnumMember.Name, EnumMember.Value
' it is left as an exercise to the reader to determine a nice way of returning this info to the calling procedure...
' This example happens to return as a list in a string, but you can choose other ways, eg a dictionary.
GetADOEnumMemberName = GetADOEnumMemberName & EnumMember.Name & " " & EnumMember.Value & vbCrLf
End If
Next
End If
Next
End Function
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: GET type of fields
WOW!SpeakEasy wrote: ↑03 Oct 2022, 10:50OK. You need a form with a textbox set to multiline (and with a vertical scrollbar enabled, preferably). You will also need to add a reference to the Typelib Information library. Then:
Code: Select all
Option Explicit ' Requires a multiline textbox (preferably with vertical scrollbar enabled) Private Sub Form_Load() Text1.Text = GetADOEnumMemberName("DataTypeEnum") End Sub ' Requires a reference to Typelib Information to be added to the project. If distributing your executable, make sure it is packaged with this library. ' This example is hardcoded to look at ADO enums, but with appropriate parameter passed to TLI.TypeLibInfoFromFile can work with any ActiveX library Public Function GetADOEnumMemberName(strEnumName As String, Optional varVal As Variant) As Variant Dim TLIApp As TLIApplication Dim myConstant As ConstantInfo Dim EnumMember As MemberInfo Dim ADOTLI As TypeLibInfo Set TLIApp = New TLIApplication ' Get our type library info from the relevant file ' This is the line that makes this example specific to the ADO object library Set ADOTLI = TLI.TypeLibInfoFromFile("c:\program files\common files\system\ado\msado15.dll") ' Loop through members of libraries constants For Each myConstant In ADOTLI.Constants If myConstant.TypeKind = TKIND_ENUM And myConstant.Name = strEnumName Then For Each EnumMember In myConstant.Members If Not IsMissing(varVal) Then Select Case TypeName(varVal) Case "String" If EnumMember.Name = varVal Then GetADOEnumMemberName = EnumMember.Value Case "Integer" If EnumMember.Value = varVal Then GetADOEnumMemberName = EnumMember.Name End Select Else ' List all members of this enum in debug window if you like ' Debug.Print EnumMember.Name, EnumMember.Value ' it is left as an exercise to the reader to determine a nice way of returning this info to the calling procedure... ' This example happens to return as a list in a string, but you can choose other ways, eg a dictionary. GetADOEnumMemberName = GetADOEnumMemberName & EnumMember.Name & " " & EnumMember.Value & vbCrLf End If Next End If Next End Function
TKS BRO.
-
- 4StarLounger
- Posts: 562
- Joined: 27 Jun 2021, 10:46
Re: GET type of fields
You might want to look at the second parameter as well - you can use it to look up a specific enumeration item either by name or by value
e.g
GetADOEnumMemberName("DataTypeEnum", 7)
will return adDate
and
GetADOEnumMemberName("DataTypeEnum", "adDate")
will return 7
e.g
GetADOEnumMemberName("DataTypeEnum", 7)
will return adDate
and
GetADOEnumMemberName("DataTypeEnum", "adDate")
will return 7
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: GET type of fields
SpeakEasy wrote: ↑03 Oct 2022, 18:47You might want to look at the second parameter as well - you can use it to look up a specific enumeration item either by name or by value
e.g
GetADOEnumMemberName("DataTypeEnum", 7)
will return adDate
and
GetADOEnumMemberName("DataTypeEnum", "adDate")
will return 7