Results 1 to 15 of 15
  1. #1
    yeah is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Nov 2010
    Posts
    61

    Intrinsic Constant Names

    When enumerating field types in a DAO recordset object, spitting out the results in the immediate window (debug window if U R a whippersnapper), I get values like 10, 12 and 2 (not very revealing). How do I print the corresponding names of intrinsic constants (like dbText, dbMemo & dbByte)?.



    I searched forums for "intrinsic constant names" B4 posting this thread. Here's the pertinent code snippet...

    For i = 0 To intFields - 1
    If IsNull(rs(i).Value) Then str = "" Else str = Trim(rs(i).Value)
    Debug.Print i + 1, rs(i).Name, rs(i).Type 'I would like to put ,rs(i).TypeIntrinsicConstantName here, if U-get my drift...
    Next i

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Frustrating, I know. You have to know where to look, and now I can't find where I got the info from, but I have a list that might help a bit. I see that I might not have all the types (e.g. is Y/N the same type number as Boolean?), but it's a start.
    TypeName DataType Desc
    Currency 5 $
    DateTime 8
    Text 10
    YN 1 yes/no
    Number 2 byte
    Number 3 integer
    Number 4 long
    Number 6 single
    Number 7 double
    Number 20 decimal
    Number 4 autonumber

    EDIT: another quick search but with different terms gave me something with vbConstant and not just numbers.
    http://www.informit.com/articles/art...39929&seqNum=2

    BTW - forgot to ask, why is your post font so large? I think you have other threads with the same thing?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    yeah is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Nov 2010
    Posts
    61
    I appreciate that. I can look them up manually online or using the Object Browser. I don't wanna do that. I wanna debug-dot-print 'em in the immediate window using the aforementioned code snippet. Am looking 4 the syntax 2 make that happen.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Doubt there is an intrinsic function or property that will return the constant name.

    Build a table and do a lookup.

    But if your reason for this code is to determine the constant name in order to build table, you are caught in catch-22 conundrum.

    What is purpose for this?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    If I understand your point, I've never found a keyword that defines a group of data type properties. Maybe this https://msdn.microsoft.com/en-us/lib.../ff193147.aspx (see the "Properties" property link). I haven't explored it, but suspect you could iterate over the Properties property collection and see if there is a keyword other than "Type". Since we have "type" I figure you won't find one. If you plan to make extensive use of such code, you might consider creating a custom property in an object module, in which case you'd need to not only append it to a recordset/table object's properties collection, you'd need to define the association between the type number and each alpha (vbSomeType) keyword.

    I found another list in case you go down that route.
    https://msdn.microsoft.com/en-us/lib.../ff845405.aspx
    just below "Remarks" is a table.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716

  7. #7
    yeah is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Nov 2010
    Posts
    61
    Quote Originally Posted by orange View Post
    Check this link DAO DataTypeEnums
    Short of creating a table of intrinsic constants and their values, does ANYONE know how to determine the
    intrinsic constant name "dbBoolean" when a value of 1 is returned by rs(i).Type in the following code snippet?
    I think we can all agree that we can find them online, memorize them, create a table of names and values.
    There's probably a book for sale somewhere with a chapter devoted to listing intrinsic constants and their values.
    I really don't wanna buy the book. Without dwelling on any of those options further, I'm curious to know if VBA
    will do the work for me. It's clear that VBA knows the value of dbBoolean is 1. In the immediate window,
    ? dbBoolean
    1
    The above 2-lines prove that. But VBA does not seem to wanna give up intrinsic constant names - just their
    values. I hope someone can prove me wrong.

    For i = 0 To intFields - 1
    If IsNull(rs(i).Value) Then str = "" Else str = Trim(rs(i).Value)
    Debug.Print i + 1, rs(i).Name, rs(i).Type
    Next i

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Here's part of an answer from another forum

    Code:
    The question: 
    Is there a way to get the enums in VBA?
      
    No - there is no native way to do this. You'd need to fully parse all of the user code and read the type libraries 
    of any loaded projects and finally determine what scope each reference was referring to.  
    
      Enumerations can't be treated like reference types in VBA, and this  due to the deep roots that VBA has in COM.  
    Enums in VBA are more like  aliases, and in fact, VBA doesn't even enforce type safety for them  (again, because 
    of COM interop - MIDL specs require that they are  treated as a DWORD).
    
      If you really need to do this in VBA, a good workaround would be to create your own enumeration class and 
    use that instead.

  9. #9
    yeah is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Nov 2010
    Posts
    61
    Thanks, Orange. Was pretty much ready to abandon the pursuit. Intrinsic constants are intuitively named, making it convenient to quickly use them to
    compare values... If MyVar = dbCurrency Then... blah blah blah keeps you from having to remember that 5 is the value associated with the dbCurrency type.

  10. #10
    yeah is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Nov 2010
    Posts
    61
    Am new to this forum. Am I supposed to flag a post as having been resolved?

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    You can. Use Thread Tools drop down above first post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    If you really need to do this in VBA, a good workaround would be to create your own enumeration class and use that instead.
    Too bad I wasn't on the ball enough to call it a class instead of an object.

    Yes, use the thread tools to mark as solved if you are done with a thread. Saves others from scanning them when they're basically finished one way or another. Thanks.

  13. #13
    yeah is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Nov 2010
    Posts
    61
    Thx, guys. Marked it so. I appreciate all the help.

  14. #14
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716

  15. #15
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    one of the problems with finding an enum name is the context. a double in dao datatypes with a value of 7 is dbDouble, in ado datatypes it is adDouble with a value of 5. in ado a value of 7 is adDate whilst a value of 5 in dao is dbCurrency. You will need to create a function with case statement code to return the name based on two parameters - the type and the value.

    You can find the values by going into vba, hit F2 and in the searchbox type 'enum'. Selecting an enum description shows the value at the bottom of the window

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Setting a constant caption for all forms
    By DubCap01 in forum Forms
    Replies: 5
    Last Post: 01-10-2015, 03:39 PM
  2. Declaring a Variable Constant (Sort Of)
    By emmahope206 in forum Programming
    Replies: 1
    Last Post: 02-27-2013, 11:15 AM
  3. Intrinsic filter tool undoes itself?
    By ConfusedDatabaseDesigner in forum Forms
    Replies: 1
    Last Post: 07-20-2012, 09:41 AM
  4. divide value by a constant and populate same field
    By ridgeview80 in forum Queries
    Replies: 5
    Last Post: 05-28-2012, 09:37 AM
  5. Replies: 1
    Last Post: 06-09-2010, 04:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums