Show Data Type

Curry

Registered User.
Local time
Tomorrow, 09:55
Joined
Jul 21, 2003
Messages
73
Hi All,

I have a List box in a form which is currently showing the Field List of a table. I also want to show the data type of each field next to each field name.

eg

Field_1 Text
Field_2 Text
Field_3 Date
Field_4 Text

I have set the List Box to column count 2 however all this does is repeat the Field name.

Is there a way of getting this. I suspect I will have to write some code that will populate the Field list as I want it, however I was hoping for a simpler way. Any thoughts would be appreciated.

IC
 
Hi All Again,

No responses to this so I assume this can't be done.....Instead I created an Option Group with the two potential data types my fields can be (Text or Date) which I named Type_Select. I then use the following code which runs when you select a field from the Field_List list box. The Option Group changes according to the data type of the selection made. When the option group is changed by the user the data type of the field changes accordingly....

This code also ensures that the datatables are located in a split database Be.mdb file.


Dim LinkedPth As String
LinkedPth = Left(CurrentProject.FullName, Len(CurrentProject.FullName) - 4) & "_be.mdb"

dbPath = LinkedPth

Dim wsp As Workspace

Set wsp = DBEngine.Workspaces(0)
Set db = wsp.OpenDatabase(dbPath)
Set tdf = db.TableDefs("tbl" & Me.Table_List)


For Each fld In tdf.Fields
Select Case fld.Name
Case Me.Field_List
If fld.Type = dbText Then
Me.Type_Select = 1
Else: Me.Type_Select = 2
End If
End Select
Next fld


Set tdf = Nothing

db.Close
Set db = Nothing



And the code for when the Option Box is changed...


If Me.Type_Select = 1 Then
db.Execute "ALTER TABLE tbl" & Me.Table_List & " ALTER COLUMN " & Me.Field_List & " TEXT;"
Me.Type_Select = 1
Else
db.Execute "ALTER TABLE tbl" & Me.Table_List & " ALTER COLUMN " & Me.Field_List & " DATE;"
Me.Type_Select = 2
End If

Hope someone finds this useful down the track.

IC
 
Last edited:

Users who are viewing this thread

Back
Top Bottom