Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to check the datatype property of a form control 2

Status
Not open for further replies.

chillwa

Programmer
Jun 16, 2008
8
US
what is the one line code to check what data type a textbox control on a form is?

I need to find out if a control is a textbox and if so, if this textbox data type is a long integer.

Any help would be appreciated.

 
Controls do not have data types, only the field contained has a data type.

Me.txtText.ControlType=acTextbox '109

Will return True is the control is a textbox.

You can check the field type from the recordset:

Code:
Set fld = Me.Recordset.Fields(Me.txtText.ControlSource)
Debug.Print CurrentDb.TableDefs(fld.SourceTable).Fields(fld.SourceField).Type = dbLong
 
If you pass Remou's field type in this function it will return the string name.

Code:
Public Function fncFldTypeToString(intFieldType As Integer) As String
  Select Case intFieldType
    Case 1
      fncFldTypeToString = "dbBoolean"
    Case 2
      fncFldTypeToString = "dbByte"
    Case 3
      fncFldTypeToString = "dbInteger"
    Case 4
      fncFldTypeToString = "dbLong"
    Case 5
       fncFldTypeToString = "dbCurrency"
    Case 6
      fncFldTypeToString = "dbSingle"
    Case 7
      fncFldTypeToString = "dbDouble"
    Case 8
      fncFldTypeToString = "dbDate"
    Case 9
      fncFldTypeToString = "dbBinary"
    Case 10
      fncFldTypeToString = "dbText"
    Case 11
      fncFldTypeToString = "dbLongBinary"
    Case 12
      fncFldTypeToString = "dbMemo"
    Case 13
      fncFldTypeToString = "Text"
    Case 14
      fncFldTypeToString = "Text"
    Case 15
      fncFldTypeToString = "dbGUID"
    Case 16
      fncFldTypeToString = "dbBigInt"
    Case 17
      fncFldTypeToString = "dbVarBinary"
    Case 18
      fncFldTypeToString = "dbChar"
    Case 19
      fncFldTypeToString = "dbNumeric"
    Case 20
      fncFldTypeToString = "dbDecimal"
    Case 21
      fncFldTypeToString = "dbFloat"
    Case 22
      fncFldTypeToString = "dbTime"
    Case 23
      fncFldTypeToString = "dbTimeStamp"
  End Select
End Function
 
The way I have set up the lines above, they will return either True or False, not a number.
 
Sorry. To be a little clearer and still using Remou's suggestion.
Code:
dim ft as long
Set fld = Me.Recordset.Fields(Me.txtText.ControlSource)
ft = CurrentDb.TableDefs(fld.SourceTable).Fields(fld.SourceField).Type
debug.print fncFldTypeToString(ft)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top