Please Advice CreateCOntrol

D

Dib

Hi,

I have an Access program in which I am using CreateControl to create labels
and CheckBoxes .

This is working fine in a .MDB copy, but I need a way to make it work in an
MDE copy an to open a Form in Design Mode is not allowed in and MDE copy.

What can I do so that I can create the Controls on a Form without giving the
User the .MDB copy

Thanks
Dib
 
A

Allen Browne

As you found, you cannot use CreateControl in an MDE.
You will need to create sufficient of each type of control for the maximum
you will ever need, and set the Visible property to True when you need them.
 
C

Cheryl Fischer

As far as I know, you cannot create controls in an MDE file.

The alternative I would suggest is to use your MDB file to create all of the
controls that you will need on the form and then create VBA code that will
make these controls Visible or Invisible, Enabled or Disabled, etc.,
according to whatever conditions are appropriate.
 
D

Dib

I need more hel p please

This is not working well for me.

Because based on the control name if it is a check box and its value is True
I am updating Data in the table based on the value of Check box .

This is what I have

Sub CreateControlOnPage()

Dim frm As Form, ctl As Control
Dim iT, iL, iW, iH, iCW, iCL As Double

Dim rs As Recordset
Dim strSQL As String

strSQL = "SELECT tblReviewDesc.Description, tblReviewDesc.Level FROM
tblReviewDesc WHERE (((tblReviewDesc.Level) =" &
[Forms]![frmreviewselection]![TxtLevel] & ")) ORDER BY
tblReviewDesc.Description;"

Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)

' DoCmd.OpenForm "frmReview", acDesign
Set frm = Forms!frmReview
strReviewString = ""
' Create a tab control on the new form.

iT = 0.3333
iL = 0.3333
iW = 1.2917
iH = 0.1667
iCW = 0.171
iCL = 1.6667
With rs
.MoveFirst
Do Until .EOF

Set ctl = CreateControl(frm.Name, acLabel, acDetail) ',
rs!ReviewofSystem)
ctl.Top = iT * 1440
ctl.Left = iL * 1440
ctl.Width = iW * 1440
ctl.Height = iH * 1440
ctl.Name = "Lbl" & rs!Description
ctl.Caption = rs!Description
ctl.FontBold = True
ctl.Visible = True
' Create a text box on the form, and specify that Page2 is
' the parent of the text box.
Set ctl = CreateControl(frm.Name, acCheckBox, acDetail) ',
rs!ReviewofSystem)
ctl.Top = iT * 1440
ctl.Left = iCL * 1440
ctl.Width = iCW * 1440
ctl.Name = rs!Description
ctl.Visible = True
iT = iT + 0.2084
.MoveNext
Loop
End With
DoCmd.SelectObject acForm, frm.Name
DoCmd.OpenForm frm.Name

End Sub


and I am doing an update to the Table this way

Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is CheckBox Then
If ctl.Value = True Then
strReviewString = strReviewString & ctl.Name & "(x)" & vbCrLf
Else
strReviewString = strReviewString & ctl.Name & "(-)" & vbCrLf
End If

End If



Next ctl

What is my second option here. Can I secure my code in all of the Program.

How can I do this without prompting the user to enter User Name or Password.

Thanks
Dib
 
A

Allen Browne

Dib, I don't understand this follow up.

The reply was that CreateControl() is not appropriate for an MDE.

Your code, using CreateControl() will not be any use for your MDE.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Dib said:
I need more hel p please

This is not working well for me.

Because based on the control name if it is a check box and its value is True
I am updating Data in the table based on the value of Check box .

This is what I have

Sub CreateControlOnPage()

Dim frm As Form, ctl As Control
Dim iT, iL, iW, iH, iCW, iCL As Double

Dim rs As Recordset
Dim strSQL As String

strSQL = "SELECT tblReviewDesc.Description, tblReviewDesc.Level FROM
tblReviewDesc WHERE (((tblReviewDesc.Level) =" &
[Forms]![frmreviewselection]![TxtLevel] & ")) ORDER BY
tblReviewDesc.Description;"

Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)

' DoCmd.OpenForm "frmReview", acDesign
Set frm = Forms!frmReview
strReviewString = ""
' Create a tab control on the new form.

iT = 0.3333
iL = 0.3333
iW = 1.2917
iH = 0.1667
iCW = 0.171
iCL = 1.6667
With rs
.MoveFirst
Do Until .EOF

Set ctl = CreateControl(frm.Name, acLabel, acDetail) ',
rs!ReviewofSystem)
ctl.Top = iT * 1440
ctl.Left = iL * 1440
ctl.Width = iW * 1440
ctl.Height = iH * 1440
ctl.Name = "Lbl" & rs!Description
ctl.Caption = rs!Description
ctl.FontBold = True
ctl.Visible = True
' Create a text box on the form, and specify that Page2 is
' the parent of the text box.
Set ctl = CreateControl(frm.Name, acCheckBox, acDetail) ',
rs!ReviewofSystem)
ctl.Top = iT * 1440
ctl.Left = iCL * 1440
ctl.Width = iCW * 1440
ctl.Name = rs!Description
ctl.Visible = True
iT = iT + 0.2084
.MoveNext
Loop
End With
DoCmd.SelectObject acForm, frm.Name
DoCmd.OpenForm frm.Name

End Sub


and I am doing an update to the Table this way

Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is CheckBox Then
If ctl.Value = True Then
strReviewString = strReviewString & ctl.Name & "(x)" & vbCrLf
Else
strReviewString = strReviewString & ctl.Name & "(-)" & vbCrLf
End If

End If



Next ctl

What is my second option here. Can I secure my code in all of the Program.

How can I do this without prompting the user to enter User Name or Password.

Thanks
Dib
Allen Browne said:
As you found, you cannot use CreateControl in an MDE.
You will need to create sufficient of each type of control for the maximum
you will ever need, and set the Visible property to True when you need them.

in
an giving
the
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top