Please Advice 2 CreateControl

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
 
M

Michel Walsh

Hi,


What do you WANT to do, as a goal, rather than HOW you are doing it?

Right now, it seems that you create "n" controls at the same position,
all with the same size, where n= number of records in the recordset you
open. That seems quite un-usual, not only to create a control, but to create
n of them, one over the other?

Would it not be preferable to create ONE control, at DESIGN TIME, but
leave in not visible, and then turn it visible as required? eventually,
change its associated label caption? That would be more standard and your
code would be cleaner, in my humble opinion. But as your code stands, I just
don't find WHAT you want to achieve, sorry. Changing a caption or changing
visibility of an existing control, through code, does not require special
security access from the end user using your application.


Vanderghast, Access MVP



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
 
D

Dib

Thanks Michel,

I am trying to create a form based on the selection from a combo box. if
the user selected from the combobox "General", this has about 5
Descriptions, the Form is creating the labels and Check boxes as per
Description so that the user can check which description he/she want to use.
if a check box is check then the user click on the close button, and the
checkbox that has a value = True will insert the Name of check box "Which is
the Description" in a textbox on a different Form.
Lets say the description is Printer" this will be on the textbox like this
"Printer(x). if none of the check boxes value are true then the descriptions
will just be
Printer(-). and the Labels and checkboxes are not created one over the
other, when the user close the form none of the labels or checkboxes are
saved. the form remains blank.




Michel Walsh said:
Hi,


What do you WANT to do, as a goal, rather than HOW you are doing it?

Right now, it seems that you create "n" controls at the same position,
all with the same size, where n= number of records in the recordset you
open. That seems quite un-usual, not only to create a control, but to create
n of them, one over the other?

Would it not be preferable to create ONE control, at DESIGN TIME, but
leave in not visible, and then turn it visible as required? eventually,
change its associated label caption? That would be more standard and your
code would be cleaner, in my humble opinion. But as your code stands, I just
don't find WHAT you want to achieve, sorry. Changing a caption or changing
visibility of an existing control, through code, does not require special
security access from the end user using your application.


Vanderghast, Access MVP



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
 
M

Michel Walsh

Hi,


Pre-create the different forms (formGeneral with its five descriptions,
formPrinter with its single description / check box). Also create a form
with nothing (fromNull).

Place formNull as SubForm in the main form.


In the AfterUpdate event of the combo box (or where appropriate), change
the SourceObject property of the subForm control:


If Me.ComboBox.Value = "General" then
Me.SubFormControl.SourceObject= "formGeneral"
ElseIf Me.ComboBox.Value="Printer" then
Me.SubFormControl.SourceObject= "formPrinter"
ElseIf
...
Else
Me.SubFormControl.SOurceObject="formNull"
End If


You can avoid the long if-elseif list (which is also a maintenance
problem) by adding an extra column in the ComboBox (not a visible column),
that will get the "form name" associated to the "selection", ie, if
Column(0)= "General", or "Printer", etc, then have Column(1)= "formGeneral",
or "formPrinter", and then, the whole if-list is just:


Me.SubFormControl.SourceObject=Nz(Me.ComboBox.Column(1).Value,
"formNull)


The concept is to display the right subform, once the type of "form" to
be used is known.

You probably have to play with the SourceObject in the onCurrent event,
if the main form is somehow bound to some record source.

Since every thing is already "built", no special privileges are to be
managed at run time.





Hoping it may help,
Vanderghast, Access MVP



Dib said:
Thanks Michel,

I am trying to create a form based on the selection from a combo box. if
the user selected from the combobox "General", this has about 5
Descriptions, the Form is creating the labels and Check boxes as per
Description so that the user can check which description he/she want to use.
if a check box is check then the user click on the close button, and the
checkbox that has a value = True will insert the Name of check box "Which is
the Description" in a textbox on a different Form.
Lets say the description is Printer" this will be on the textbox like this
"Printer(x). if none of the check boxes value are true then the descriptions
will just be
Printer(-). and the Labels and checkboxes are not created one over the
other, when the user close the form none of the labels or checkboxes are
saved. the form remains blank.




Michel Walsh said:
Hi,


What do you WANT to do, as a goal, rather than HOW you are doing it?

Right now, it seems that you create "n" controls at the same position,
all with the same size, where n= number of records in the recordset you
open. That seems quite un-usual, not only to create a control, but to create
n of them, one over the other?

Would it not be preferable to create ONE control, at DESIGN TIME, but
leave in not visible, and then turn it visible as required? eventually,
change its associated label caption? That would be more standard and your
code would be cleaner, in my humble opinion. But as your code stands, I just
don't find WHAT you want to achieve, sorry. Changing a caption or changing
visibility of an existing control, through code, does not require special
security access from the end user using your application.


Vanderghast, Access MVP



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
 

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