PC Review


Reply
Thread Tools Rate Thread

Determining the Data Type of a Field

 
 
Mr. JYC
Guest
Posts: n/a
 
      30th Sep 2008
Hello,

How can one determine the data type of a field programmatically?

--
Thank you for your help!
JYC
 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      30th Sep 2008
In what context?

If this is in a form, examine the ControlSource of the text box to get the
field name. Then examine:
Me.Recordset.Fields("SomeFieldName").Type

The result will be one of the dbDataTypeEnum constants. To convert it to
English text, see the FieldTypeName() function here:
http://allenbrowne.com/func-06.html

If you need to read the data type of the field directly from the table, the
TableInfo() function in the link above will do that.

--
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.

"Mr. JYC" <(E-Mail Removed)> wrote in message
news:F0D6E5A3-E0AF-4D5D-B39F-(E-Mail Removed)...
> Hello,
>
> How can one determine the data type of a field programmatically?
>
> --
> Thank you for your help!
> JYC


 
Reply With Quote
 
Mr. JYC
Guest
Posts: n/a
 
      30th Sep 2008
Thank you for your response Allen. The information will come in handy soon.
I was confused. I guess that is why the question did not make sense. I
actually wanted to find out the data type of a text box control. Is there a
way to do this?

--
Thank you for your help!
JYC


"Allen Browne" wrote:

> In what context?
>
> If this is in a form, examine the ControlSource of the text box to get the
> field name. Then examine:
> Me.Recordset.Fields("SomeFieldName").Type
>
> The result will be one of the dbDataTypeEnum constants. To convert it to
> English text, see the FieldTypeName() function here:
> http://allenbrowne.com/func-06.html
>
> If you need to read the data type of the field directly from the table, the
> TableInfo() function in the link above will do that.
>
> --
> 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.
>
> "Mr. JYC" <(E-Mail Removed)> wrote in message
> news:F0D6E5A3-E0AF-4D5D-B39F-(E-Mail Removed)...
> > Hello,
> >
> > How can one determine the data type of a field programmatically?
> >
> > --
> > Thank you for your help!
> > JYC

>
>

 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      30th Sep 2008
A control doesn't have a data type.

If it is bound to a field, the field determines the data type.

If is is unbound, you can use the Format property to give Access the clue
about what data type you intend it to be.

For an example, see:
http://allenbrowne.com/AppFindAsUTypeCode.html
The code loops through the controls in a form, and itentifies the text boxes
and combos. It skips the unbound controls and those bound to an expression,
and identifies the name of the field the control is bound to. It than
examines the Type of this field in the form's RecordsetClone, with this
line:
Select Case rs(strControlSource).Type

Ultimately the example loads the information into the columns of an unbound
combo you can use to filter the form, with the data type in the last
(hidden) column. That's going further than you need, but that's the process.

--
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.

"Mr. JYC" <(E-Mail Removed)> wrote in message
news:8B44F30A-AB74-4753-B3AA-(E-Mail Removed)...
> Thank you for your response Allen. The information will come in handy
> soon.
> I was confused. I guess that is why the question did not make sense. I
> actually wanted to find out the data type of a text box control. Is there
> a
> way to do this?
>
> --
> Thank you for your help!
> JYC
>
>
> "Allen Browne" wrote:
>
>> In what context?
>>
>> If this is in a form, examine the ControlSource of the text box to get
>> the
>> field name. Then examine:
>> Me.Recordset.Fields("SomeFieldName").Type
>>
>> The result will be one of the dbDataTypeEnum constants. To convert it to
>> English text, see the FieldTypeName() function here:
>> http://allenbrowne.com/func-06.html
>>
>> If you need to read the data type of the field directly from the table,
>> the
>> TableInfo() function in the link above will do that.
>>
>> --
>> 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.
>>
>> "Mr. JYC" <(E-Mail Removed)> wrote in message
>> news:F0D6E5A3-E0AF-4D5D-B39F-(E-Mail Removed)...
>> > Hello,
>> >
>> > How can one determine the data type of a field programmatically?


 
Reply With Quote
 
Mr. JYC
Guest
Posts: n/a
 
      30th Sep 2008
Come to think of it, how do you programatically determine the data type of a
variable that may contain any one of the data types supported in Access?
--
Thank you for your help!
JYC


"Allen Browne" wrote:

> In what context?
>
> If this is in a form, examine the ControlSource of the text box to get the
> field name. Then examine:
> Me.Recordset.Fields("SomeFieldName").Type
>
> The result will be one of the dbDataTypeEnum constants. To convert it to
> English text, see the FieldTypeName() function here:
> http://allenbrowne.com/func-06.html
>
> If you need to read the data type of the field directly from the table, the
> TableInfo() function in the link above will do that.
>
> --
> 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.
>
> "Mr. JYC" <(E-Mail Removed)> wrote in message
> news:F0D6E5A3-E0AF-4D5D-B39F-(E-Mail Removed)...
> > Hello,
> >
> > How can one determine the data type of a field programmatically?
> >
> > --
> > Thank you for your help!
> > JYC

>
>

 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      30th Sep 2008
"Mr. JYC" <(E-Mail Removed)> wrote in message
news04683F1-1FCF-4180-91C9-(E-Mail Removed)...
> Come to think of it, how do you programatically determine the data type of
> a
> variable that may contain any one of the data types supported in Access?


VarType()

--
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.

 
Reply With Quote
 
Mr. JYC
Guest
Posts: n/a
 
      30th Sep 2008
Thank you Allen!
--
Thank you for your help!
JYC


"Allen Browne" wrote:

> "Mr. JYC" <(E-Mail Removed)> wrote in message
> news04683F1-1FCF-4180-91C9-(E-Mail Removed)...
> > Come to think of it, how do you programatically determine the data type of
> > a
> > variable that may contain any one of the data types supported in Access?

>
> VarType()
>
> --
> 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.
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determining the data type. satadru Microsoft Excel Misc 5 8th Sep 2008 08:39 AM
Determining field type CHAR vs VARCHAR Jared Microsoft ADO .NET 3 14th Jul 2006 08:30 PM
Determining native database data type? Andy Microsoft ADO .NET 0 8th Nov 2005 08:18 PM
Question for Joe Fallon--determining Data type cb Microsoft Access External Data 3 14th Oct 2004 01:53 PM
Reflection: determining whether Type of field is signed or unsigned Laszlo Szijarto Microsoft C# .NET 2 6th Jan 2004 12:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:52 AM.