Where is the Data Control?

Where is the Data Control?

Anonymous
Not applicable
176 Views
4 Replies
Message 1 of 5

Where is the Data Control?

Anonymous
Not applicable
I am trying to populate a combobox on a form with values from an Access
database. In standalone VBA i use a DATACONTROL. However, I cant find it in
the Autocad VB environment (i checked references and objects).
Can anyone help?
0 Likes
177 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
This is a bit of code I've been using to populate a listbox from an Access
database file in VBA. You'll have to modify it to match your db fields,
etc. You'll also have to load the ADO 2.5 reference. I'm still working on
making it a bit more robust, but I know it works. It probably makes more
sense to load the record set information into an array and then populate the
listbox using the array.

I've never seen or used the DATACONTROL object. Is that VB6?

Private Sub UserForm_Initialize()
' Set initial values for controls on form.

Dim strConnect, strCriteria As String
Dim conAECParts As New Connection
Dim rsParts, rsCategories As New Recordset
Dim intCount As Integer
Dim fldParts As Field

strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\My Documents\AECCALogs.mdb;" & _
"Persist Security Info=False"

conAECParts.Open strConnect
rsParts.Open "tblParts", conAECParts, adOpenStatic, adLockReadOnly,
adCmdTable
' Substitute "tblParts" with a SQL string & change adCmdTable to adCmdText

rsCategories.Open "tblCategories", conAECParts, adOpenStatic,
adLockReadOnly, adCmdTable

strCriteria = "Folder LIKE 'Steel'"
rsParts.Filter = strCriteria

While Not rsParts.EOF
ListBox1.AddItem rsParts.Fields("File").Value
'Debug.Print rsParts.Fields("File").Value
rsParts.MoveNext
Wend

rsParts.Close
conAECParts.Close
Set rsParts = Nothing
Set conAECParts = Nothing

End Sub

Brian Johnson

"CAD MAN" wrote in message
news:47746D716800D295D0C48BD96819FFF8@in.WebX.SaUCah8kaAW...
> I am trying to populate a combobox on a form with values from an Access
> database. In standalone VBA i use a DATACONTROL. However, I cant find it
in
> the Autocad VB environment (i checked references and objects).
> Can anyone help?
>
0 Likes
Message 3 of 5

Anonymous
Not applicable
I am trying to place some sort of a data control on my form that will link
to an access database. Then i want to have a text box (or similar) gets its
values from the data control (database). In VBA 6 i insert a DATA Control
and link it to a database-table-field. I cant figure out how to do this in
Autocad VB.

I can insert an ADO control but what can I link to it? list boxes, text
boxes atc cant seem to get their values from it.
-Sean

"Brian Johnson" wrote in message
news:F266400C178BBFAAF46F6CB62525D8EF@in.WebX.SaUCah8kaAW...
> This is a bit of code I've been using to populate a listbox from an Access
> database file in VBA. You'll have to modify it to match your db fields,
> etc. You'll also have to load the ADO 2.5 reference. I'm still working
on
> making it a bit more robust, but I know it works. It probably makes more
> sense to load the record set information into an array and then populate
the
> listbox using the array.
>
> I've never seen or used the DATACONTROL object. Is that VB6?
>
> Private Sub UserForm_Initialize()
> ' Set initial values for controls on form.
>
> Dim strConnect, strCriteria As String
> Dim conAECParts As New Connection
> Dim rsParts, rsCategories As New Recordset
> Dim intCount As Integer
> Dim fldParts As Field
>
> strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> "Data Source=C:\My Documents\AECCALogs.mdb;" & _
> "Persist Security Info=False"
>
> conAECParts.Open strConnect
> rsParts.Open "tblParts", conAECParts, adOpenStatic, adLockReadOnly,
> adCmdTable
> ' Substitute "tblParts" with a SQL string & change adCmdTable to adCmdText
>
> rsCategories.Open "tblCategories", conAECParts, adOpenStatic,
> adLockReadOnly, adCmdTable
>
> strCriteria = "Folder LIKE 'Steel'"
> rsParts.Filter = strCriteria
>
> While Not rsParts.EOF
> ListBox1.AddItem rsParts.Fields("File").Value
> 'Debug.Print rsParts.Fields("File").Value
> rsParts.MoveNext
> Wend
>
> rsParts.Close
> conAECParts.Close
> Set rsParts = Nothing
> Set conAECParts = Nothing
>
> End Sub
>
> Brian Johnson
>
> "CAD MAN" wrote in message
> news:47746D716800D295D0C48BD96819FFF8@in.WebX.SaUCah8kaAW...
> > I am trying to populate a combobox on a form with values from an Access
> > database. In standalone VBA i use a DATACONTROL. However, I cant find it
> in
> > the Autocad VB environment (i checked references and objects).
> > Can anyone help?
> >
>
0 Likes
Message 4 of 5

Anonymous
Not applicable
Sean,

I've never used the stand alone VB6, so I don't understand how exactly the
data control feature works. I have used the ADO connection code for both
VBA in AutoCAD 2000 and in some Active Server Pages scripts.

The only way I know how to populate a form control like a listbox or
combobox is to:

1. Create the form & insert a listbox control and a textbox...say Listbox1 &
Testbox1.
2. Populate the listbox control using the Initialize event of the form.
3. Update the textbox using the Change event of the listbox.

This effectively uses the Access database as the Data Source. The following
is some generic code and is untested. But it should get you started.

Private Sub UserForm_Initialize()
' Set initial values for controls on form.

Dim strConnect As String
Dim conObject As New Connection
Dim rsObject As New Recordset

' Set ADO connection string
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=Absolute_Path;" & _
"Persist Security Info=False"

' Open ADO connection & recordsets
conObject.Open strConnect
rsObject.Open "My_Table", conObject, adOpenStatic, adLockReadOnly,
adCmdTable

' Populate Listbox1 with values from the "My_Field" field in the recordset
While Not rsObject.EOF
ListBox1.AddItem rsObject.Fields("My_Field").Value
rsObject.MoveNext
Wend

' Close recordsets & ADO connection
rsObject.Close
conObject.Close
Set rsObject = Nothing
Set conObject = Nothing

End Sub

Private Sub Listbox1_Change()
' Updates the Textbox1 value.

Textbox1.Text = Listbox1.Value

End Sub

Hope this helps.

Brian

"CAD MAN" wrote in message
news:8213966DCA3C287C32F34E125B58B79A@in.WebX.SaUCah8kaAW...
> I am trying to place some sort of a data control on my form that will link
> to an access database. Then i want to have a text box (or similar) gets
its
> values from the data control (database). In VBA 6 i insert a DATA Control
> and link it to a database-table-field. I cant figure out how to do this in

> Autocad VB.
>
> I can insert an ADO control but what can I link to it? list boxes, text
> boxes atc cant seem to get their values from it.
> -Sean
>
> "Brian Johnson" wrote in message
> news:F266400C178BBFAAF46F6CB62525D8EF@in.WebX.SaUCah8kaAW...
> > This is a bit of code I've been using to populate a listbox from an
Access
> > database file in VBA. You'll have to modify it to match your db fields,
> > etc. You'll also have to load the ADO 2.5 reference. I'm still working
> on
> > making it a bit more robust, but I know it works. It probably makes
more
> > sense to load the record set information into an array and then populate
> the
> > listbox using the array.
> >
> > I've never seen or used the DATACONTROL object. Is that VB6?
> >
> > Private Sub UserForm_Initialize()
> > ' Set initial values for controls on form.
> >
> > Dim strConnect, strCriteria As String
> > Dim conAECParts As New Connection
> > Dim rsParts, rsCategories As New Recordset
> > Dim intCount As Integer
> > Dim fldParts As Field
> >
> > strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> > "Data Source=C:\My Documents\AECCALogs.mdb;" & _
> > "Persist Security Info=False"
> >
> > conAECParts.Open strConnect
> > rsParts.Open "tblParts", conAECParts, adOpenStatic, adLockReadOnly,
> > adCmdTable
> > ' Substitute "tblParts" with a SQL string & change adCmdTable to
adCmdText
> >
> > rsCategories.Open "tblCategories", conAECParts, adOpenStatic,
> > adLockReadOnly, adCmdTable
> >
> > strCriteria = "Folder LIKE 'Steel'"
> > rsParts.Filter = strCriteria
> >
> > While Not rsParts.EOF
> > ListBox1.AddItem rsParts.Fields("File").Value
> > 'Debug.Print rsParts.Fields("File").Value
> > rsParts.MoveNext
> > Wend
> >
> > rsParts.Close
> > conAECParts.Close
> > Set rsParts = Nothing
> > Set conAECParts = Nothing
> >
> > End Sub
> >
> > Brian Johnson
> >
> > "CAD MAN" wrote in message
> > news:47746D716800D295D0C48BD96819FFF8@in.WebX.SaUCah8kaAW...
> > > I am trying to populate a combobox on a form with values from an
Access
> > > database. In standalone VBA i use a DATACONTROL. However, I cant find
it
> > in
> > > the Autocad VB environment (i checked references and objects).
> > > Can anyone help?
> > >
> >
>
0 Likes
Message 5 of 5

Anonymous
Not applicable
I've been working with AutoCAD VBA & ADO. Here's a snapshot of some of my
installed libraries. I have MS-Visual Studio V6.0 (SP3) installed with all
data handling libraries selected, MS Data Access SDK V2.0 w/ V2.1 update &
misc. other updates. Doc's for most of these are on the MSDN CD.

Microsoft ActiveX Data Objects 2.1 Library:
C:\PROGRAM FILES\COMMON FILES\SYSTEM\ADO\msado15.dll
The main ADO library, of course.

Microsoft ADO Data Control 6.0 (SP3) (OLEDB):
C:\WINDOWS\SYSTEM\MSADODC.OCX
Contains only a "ADODC" class.

Microsoft DataGrid Control 6.0 (SP3) (OLEDB)
C:\WINDOWS\SYSTEM\MSDATGRD.OCX or
C:\WINDOWS\SYSTEM\MSDataGridLib.TWD
Data grid control, one of a few available.

Microsoft DataCombo & DataList Control 6.0 (SP3) (OLEDB):
C:\WINDOWS\SYSTEM\MSDATLST.OCX
Data-aware combo & listbox controls, unfortunately no data-aware textbox.

Microsoft Data Binding Collection:
C:\WINDOWS\SYSTEM\MSBIND.DLL
This is an (almost secret) library that provides the ability to bind and
form control to any data source (e.g. plain textbox to ADO recordset field).

Microsoft Data Source Interfaces:
C:\WINDOWS\SYSTEM\msdatsrc.tlb
This library may have come in with one of the other libraries. Contains
only a "Datasource" class.

--
John Goodfellow
use 'microtouch' in address to email

"CAD MAN" wrote in message
news:47746D716800D295D0C48BD96819FFF8@in.WebX.SaUCah8kaAW...
> I am trying to populate a combobox on a form with values from an Access
> database. In standalone VBA i use a DATACONTROL. However, I cant find it
in
> the Autocad VB environment (i checked references and objects).
> Can anyone help?
>
0 Likes