[AccessD] data type for field in a closed table

Gustav Brock gustav at cactus.dk
Sat Jan 24 13:21:14 CST 2004


Hi Susan

> I'm trying to return a field's data type.

> I have the field by name -- as a string -- and I just can't seem to get it
> into a Field object variable so I can tap into the Type property. The field
> is the result of a listbox selection.

> varField = lstField.Value

> How can I get from there to

> fld = varField

> to here

> varType = fld.Type

> Everything I've tried returns an Object required at the fld=varField
> statement because varField is a string, not a real reference. At least, I
> think that's the problem.

Something like this? If the rowsource is an SQL string:

  Dim dbs         As Database
  Dim qdf         As QueryDef
  dim intVarType  As Integer
  
  Set dbs = CurrentDb()
  Set qdf = dbs.CreateQueryDef(vbNullString)
  qdf.SQL = Me!lstDemo.RowSource
  
  intVarType = qdf.Fields("YourFieldName").Type
  Debug.Print intVarType
  
  qdf.Close
  
  Set qdf = Nothing
  Set dbs = Nothing

If not an SQL string, just pick the name of the stored query and use
that as qdf.

/gustav



More information about the AccessD mailing list