I am working on a database in which I will have different data types. What I
want to be able to do is if, for example, the field [datatype] equals 1 it
would display a text box on the form, if 2 a combo box, if 3 a list box, etc.
Any suggestions?
In order to create controls in code, you must either open a form in Design
View, or have the controls in place and expose them at runtime.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
> I am working on a database in which I will have different data types. What I
> want to be able to do is if, for example, the field [datatype] equals 1 it
> would display a text box on the form, if 2 a combo box, if 3 a list box, etc.
> Any suggestions?
Steve Voorhees - 18 Nov 2005 10:37 GMT
I have written some code on controls before, but my problem is that I am not
sure how to do something of this nature, or even if it would be possible.
> In order to create controls in code, you must either open a form in Design
> View, or have the controls in place and expose them at runtime.
[quoted text clipped - 11 lines]
> etc.
> > Any suggestions?
Brendan Reynolds - 18 Nov 2005 11:05 GMT
You can create controls using the CreateControl method of the Form object,
but as Arvin says, you have to open the form in design view to do that. It's
generally better to create the controls in advance, and just toggle their
Visible property at run time. For example ...
Private Sub Form_Open(Cancel As Integer)
Dim FieldType As Long
FieldType = Me.Recordset.Fields(0).Type
Select Case FieldType
Case dbLong
Me.Text28.Visible = True
Me.Combo30.Visible = False
Me.List32.Visible = False
Case Else
Me.Text28.Visible = False
Me.Combo30.Visible = True
Me.List32.Visible = True
End Select
End Sub

Signature
Brendan Reynolds
>I have written some code on controls before, but my problem is that I am
>not
[quoted text clipped - 18 lines]
>> etc.
>> > Any suggestions?