Access Form Control List

B

balu

Hi,

I am doing the conversion process of access 97 forms to Vb forms.In VB,i
tried makiing the access form as active forms and used the contols.count
property but it not working.

Could i get the exact the command for getting the control list in access
forms from Vb code
 
D

Douglas J. Steele

To be honest, I'm not sure you can set the active form to an Access form in
VB (unless you're using Automation). What code are you currently using?
 
B

balu

Hi,

Thank you very much for your reply.I am coding in VB
Here is the code.

Dim AccessApp As Access.Application
Set AccessApp = New Access.Application
With AccessApp
.OpenCurrentDatabase App.Path & "\ClmCD97.mdb"
Dim frm As Form
For Each frm In AccessApp.Forms
For Each ctl In frm.Controls
MsgBox ctl
Next ctl
Next frm
End With
 
D

Douglas J. Steele

Try:

Dim AccessApp As Access.Application
Dim strOutput As String
Set AccessApp = New Access.Application
With AccessApp
.OpenCurrentDatabase App.Path & "\ClmCD97.mdb"
Dim frm As Form
Dim ctl As Control
For Each frm In AccessApp.Forms
strOutput = "Form " & frm.Name & _
" has the following " & frm.Controls.Count & _
" controls:" & vbCrLf
For Each ctl In frm.Controls
strOutput = strOutput & ctl.Name
Next ctl
MsgBox strOutput
Next frm
End With
 
D

Dirk Goldgar

Douglas J. Steele said:
Try:

Dim AccessApp As Access.Application
Dim strOutput As String
Set AccessApp = New Access.Application
With AccessApp
.OpenCurrentDatabase App.Path & "\ClmCD97.mdb"
Dim frm As Form
Dim ctl As Control
For Each frm In AccessApp.Forms
strOutput = "Form " & frm.Name & _
" has the following " & frm.Controls.Count & _
" controls:" & vbCrLf
For Each ctl In frm.Controls
strOutput = strOutput & ctl.Name
Next ctl
MsgBox strOutput
Next frm
End With

But ... if you've just opened the database in AccessApp, the chances are
pretty good that the Forms collection is empty. I think you'll need to
drill down to the Forms document container.
 
B

balu

Hi Dirk,

Thank you for your response.

Forms is empty here as you mentioned for opening the access by
accessapp.But, how to get the control list for each form in the access
application by forms documents containers method.Could i get the code for
this.
 
D

Dirk Goldgar

balu said:
Hi Dirk,

Thank you for your response.

Forms is empty here as you mentioned for opening the access by
accessapp.But, how to get the control list for each form in the access
application by forms documents containers method.Could i get the code
for this.

I haven't tested it, but you might try something like this:

'------ start of code ------
Dim AccessApp As Access.Application
Dim db As DAO.Database
Dim cnt As DAO.Container
Dim doc As DAO.Document
Dim frm As Access.Form
Dim ctl As Access.Control

Dim strOutput As String

Set AccessApp = New Access.Application
With AccessApp

.OpenCurrentDatabase app.path & "\ClmCD97.mdb"
Set db = .CurrentDb
Set cnt = db.Containers("Forms")

For Each doc In cnt.Documents
.DoCmd.OpenForm doc.Name, acDesign, _
WindowMode:=acHidden
Set frm = .Forms(doc.Name)
strOutput = "Form " & frm.Name & _
" has the following " & frm.Controls.Count & _
" controls:" & vbCrLf
For Each ctl In frm.Controls
strOutput = strOutput & ctl.Name & ", "
Next ctl
.DoCmd.Close acForm, frm.Name, acSaveNo
Set frm = Nothing
If right(strOutput, 2) = ", " Then
strOutput = Left(strOutput, Len(strOutput) - 2)
End If
MsgBox strOutput
Next doc

Set doc = Nothing
Set db = Nothing

.Quit acQuitSaveNone

End With
'------ end of code ------
 
B

balu

Hi Dirk,

Similarly, i want to copy the same ctl whichever in the form list to current
vb application forms,it's giving typecating error .
I tried for ctype also but it's not working.
Here in the code
Set ctl = Controls.Add("VB.TextBox", "text1")
Set ctl.Container = Form1
 
D

Dirk Goldgar

balu said:
Hi Dirk,

Similarly, i want to copy the same ctl whichever in the form list to
current vb application forms,it's giving typecating error .
I tried for ctype also but it's not working.
Here in the code
Set ctl = Controls.Add("VB.TextBox", "text1")
Set ctl.Container = Form1

But now I'm not sure what's going on, and in what environment: Access or
VB. You need to be aware that VB controls and forms are not compatible
types with their Access analogues. If you're doing this in VB, I must
say I've never done that and am not familiar with the necessary syntax.
In that case, you may be better off asking questions related to that
particular aspect of your project in one of the newsgroups devoted to
Visual Basic (classic VB, that is).

I do know that there are several products out there that are designed to
convert Access applications to VB. It's my understanding that none of
them does a complete job, but I haven't evaluated any of them
personally.
 
Top