dbTalk Databases Forums  

Form on the fly - VBA

comp.databases.ms-access comp.databases.ms-access


Discuss Form on the fly - VBA in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
bsn
 
Posts: n/a

Default Form on the fly - VBA - 03-19-2011 , 06:19 PM






Hi NG

I am making a form on the fly - it works fine, but...

In the form i have a With statement :

With frm
.Visible = False
.Caption = "Ledige tider"
.OnOpen = "Private Sub Form_Open(Cancel As Integer)" & vbCrLf & _
" Const conInchesToTwips = 1440" & vbCrLf & _
" Dim intRight As Integer, intDown As Integer, intWidth As
Integer, intHeight As Integer" & vbCrLf & _
" DoCmd.Restore" & vbCrLf & _
" intRight = (3 * conInchesToTwips)" & vbCrLf & _
" intDown = 0" & vbCrLf & _
" intWidth = (5 * conInchesToTwips)" & vbCrLf & _
" intHeight = (5.5 * conInchesToTwips)" & vbCrLf & _
" DoCmd.MoveSize intRight, intDown, intWidth, intHeight" &
vbCrLf & _
" End Sub"
End With

The .OnOpen part do not work...
How can i write the code in Open procedure in the With statement, so it
works...???

Thx in advance...

Bjarne
"Every day new surprises"

Reply With Quote
  #2  
Old   
Stuart McCall
 
Posts: n/a

Default Re: Form on the fly - VBA - 03-19-2011 , 08:07 PM






"bsn" <bsnSNABELAoncableDOTdk> wrote

Quote:
Hi NG

I am making a form on the fly - it works fine, but...

In the form i have a With statement :

With frm
.Visible = False
.Caption = "Ledige tider"
.OnOpen = "Private Sub Form_Open(Cancel As Integer)" & vbCrLf & _
" Const conInchesToTwips = 1440" & vbCrLf & _
" Dim intRight As Integer, intDown As Integer, intWidth As
Integer, intHeight As Integer" & vbCrLf & _
" DoCmd.Restore" & vbCrLf & _
" intRight = (3 * conInchesToTwips)" & vbCrLf & _
" intDown = 0" & vbCrLf & _
" intWidth = (5 * conInchesToTwips)" & vbCrLf & _
" intHeight = (5.5 * conInchesToTwips)" & vbCrLf & _
" DoCmd.MoveSize intRight, intDown, intWidth, intHeight" &
vbCrLf & _
" End Sub"
End With

The .OnOpen part do not work...
How can i write the code in Open procedure in the With statement, so it
works...???

Thx in advance...

Bjarne
"Every day new surprises"
You can't. The code must be written inside the Form_Open procedure; that is:
everything following the first vbCrLf up to but not including the End Sub
line.

Reply With Quote
  #3  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Form on the fly - VBA - 03-19-2011 , 08:22 PM



bsn wrote:

Quote:
I am making a form on the fly - it works fine, but...

In the form i have a With statement :

With frm
.Visible = False
.Caption = "Ledige tider"
.OnOpen = "Private Sub Form_Open(Cancel As Integer)" & vbCrLf & _
" Const conInchesToTwips = 1440" & vbCrLf & _
" Dim intRight As Integer, intDown As Integer, intWidth As
Integer, intHeight As Integer" & vbCrLf & _
" DoCmd.Restore" & vbCrLf & _
" intRight = (3 * conInchesToTwips)" & vbCrLf & _
" intDown = 0" & vbCrLf & _
" intWidth = (5 * conInchesToTwips)" & vbCrLf & _
" intHeight = (5.5 * conInchesToTwips)" & vbCrLf & _
" DoCmd.MoveSize intRight, intDown, intWidth, intHeight" &
vbCrLf & _
" End Sub"
End With

The .OnOpen part do not work...
How can i write the code in Open procedure in the With statement, so it
works...???

You have to open the form's module and use the methods of
the Module object to insert the code into the module. You
would then set the OnOpen PROPERTY to:
[Event Procedure]

I must say that creating a form object and controls on the
fly is a really bad idea except when you are creating a
DESIGN TIME wizard to help yourself design forms. It can be
a whole truck load of trouble when done in a running
application.

There is almost never a valid reason to not use a prebuilt
form with precreated controls and set their properties as
needed when the form is opened.

--
Marsh

Reply With Quote
  #4  
Old   
bsn
 
Posts: n/a

Default Re: Form on the fly - VBA - 03-20-2011 , 12:45 AM



"Marshall Barton" <marshbarton (AT) wowway (DOT) com> skrev i en meddelelse
news:5joao610u2q73ihl7r913aig654cenb4ju (AT) 4ax (DOT) com...
Quote:
bsn wrote:

I am making a form on the fly - it works fine, but...

In the form i have a With statement :

With frm
.Visible = False
.Caption = "Ledige tider"
.OnOpen = "Private Sub Form_Open(Cancel As Integer)" & vbCrLf & _
" Const conInchesToTwips = 1440" & vbCrLf & _
" Dim intRight As Integer, intDown As Integer, intWidth As
Integer, intHeight As Integer" & vbCrLf & _
" DoCmd.Restore" & vbCrLf & _
" intRight = (3 * conInchesToTwips)" & vbCrLf & _
" intDown = 0" & vbCrLf & _
" intWidth = (5 * conInchesToTwips)" & vbCrLf & _
" intHeight = (5.5 * conInchesToTwips)" & vbCrLf & _
" DoCmd.MoveSize intRight, intDown, intWidth, intHeight" &
vbCrLf & _
" End Sub"
End With

The .OnOpen part do not work...
How can i write the code in Open procedure in the With statement, so it
works...???


You have to open the form's module and use the methods of
the Module object to insert the code into the module. You
would then set the OnOpen PROPERTY to:
[Event Procedure]

I must say that creating a form object and controls on the
fly is a really bad idea except when you are creating a
DESIGN TIME wizard to help yourself design forms. It can be
a whole truck load of trouble when done in a running
application.

There is almost never a valid reason to not use a prebuilt
form with precreated controls and set their properties as
needed when the form is opened.
The forms Source is a crosstabquery...
Then if there comes a colown more, it dont appear in the form...:-(
Maybee u know a better way...???
Bjarne

Reply With Quote
  #5  
Old   
bsn
 
Posts: n/a

Default Re: Form on the fly - VBA - 03-20-2011 , 01:14 AM



"bsn" <bsnSNABELAoncableDOTdk> skrev i en meddelelse
news:4d85a2a5$0$56785$edfadb0f (AT) dtext02 (DOT) news.tele.dk...
Quote:
"Marshall Barton" <marshbarton (AT) wowway (DOT) com> skrev i en meddelelse
news:5joao610u2q73ihl7r913aig654cenb4ju (AT) 4ax (DOT) com...
bsn wrote:

I am making a form on the fly - it works fine, but...

In the form i have a With statement :

With frm
.Visible = False
.Caption = "Ledige tider"
.OnOpen = "Private Sub Form_Open(Cancel As Integer)" & vbCrLf & _
" Const conInchesToTwips = 1440" & vbCrLf & _
" Dim intRight As Integer, intDown As Integer, intWidth As
Integer, intHeight As Integer" & vbCrLf & _
" DoCmd.Restore" & vbCrLf & _
" intRight = (3 * conInchesToTwips)" & vbCrLf & _
" intDown = 0" & vbCrLf & _
" intWidth = (5 * conInchesToTwips)" & vbCrLf & _
" intHeight = (5.5 * conInchesToTwips)" & vbCrLf & _
" DoCmd.MoveSize intRight, intDown, intWidth, intHeight" &
vbCrLf & _
" End Sub"
End With

The .OnOpen part do not work...
How can i write the code in Open procedure in the With statement, so it
works...???


You have to open the form's module and use the methods of
the Module object to insert the code into the module. You
would then set the OnOpen PROPERTY to:
[Event Procedure]

I must say that creating a form object and controls on the
fly is a really bad idea except when you are creating a
DESIGN TIME wizard to help yourself design forms. It can be
a whole truck load of trouble when done in a running
application.

There is almost never a valid reason to not use a prebuilt
form with precreated controls and set their properties as
needed when the form is opened.

The forms Source is a crosstabquery...
Then if there comes a colown more, it dont appear in the form...:-(
Maybee u know a better way...???
Sorry, it was the size of the form, when it opens there where the issue...
The colown problem are solved...

Bjarne

Reply With Quote
  #6  
Old   
agiamb
 
Posts: n/a

Default Re: Form on the fly - VBA - 03-20-2011 , 06:38 AM



What I would do is add an ample number of controls to the form at design
time, then at run time, set each control's source to the correct column (or
to nothing) and make it visible (or not). Seems much simpler to me than
creating a form at runtime. Especially for maintenance down the road when
client wants more features added to the form.
I have done similar with reports based on crosstab data and it works well.

--

AG
Email: npATadhdataDOTcom


"bsn" <bsnSNABELAoncableDOTdk> wrote

Quote:
"Marshall Barton" <marshbarton (AT) wowway (DOT) com> skrev i en meddelelse
news:5joao610u2q73ihl7r913aig654cenb4ju (AT) 4ax (DOT) com...
bsn wrote:

I am making a form on the fly - it works fine, but...

In the form i have a With statement :

With frm
.Visible = False
.Caption = "Ledige tider"
.OnOpen = "Private Sub Form_Open(Cancel As Integer)" & vbCrLf & _
" Const conInchesToTwips = 1440" & vbCrLf & _
" Dim intRight As Integer, intDown As Integer, intWidth As
Integer, intHeight As Integer" & vbCrLf & _
" DoCmd.Restore" & vbCrLf & _
" intRight = (3 * conInchesToTwips)" & vbCrLf & _
" intDown = 0" & vbCrLf & _
" intWidth = (5 * conInchesToTwips)" & vbCrLf & _
" intHeight = (5.5 * conInchesToTwips)" & vbCrLf & _
" DoCmd.MoveSize intRight, intDown, intWidth, intHeight" &
vbCrLf & _
" End Sub"
End With

The .OnOpen part do not work...
How can i write the code in Open procedure in the With statement, so it
works...???


You have to open the form's module and use the methods of
the Module object to insert the code into the module. You
would then set the OnOpen PROPERTY to:
[Event Procedure]

I must say that creating a form object and controls on the
fly is a really bad idea except when you are creating a
DESIGN TIME wizard to help yourself design forms. It can be
a whole truck load of trouble when done in a running
application.

There is almost never a valid reason to not use a prebuilt
form with precreated controls and set their properties as
needed when the form is opened.

The forms Source is a crosstabquery...
Then if there comes a colown more, it dont appear in the form...:-(
Maybee u know a better way...???
Bjarne

Reply With Quote
  #7  
Old   
Phil
 
Posts: n/a

Default Re: Form on the fly - VBA - 03-20-2011 , 07:13 AM



On 20/03/2011 12:38:00, "agiamb" wrote:
Quote:
What I would do is add an ample number of controls to the form at design
time, then at run time, set each control's source to the correct column
(or to nothing) and make it visible (or not). Seems much simpler to me
than creating a form at runtime. Especially for maintenance down the road
when client wants more features added to the form.
I have done similar with reports based on crosstab data and it works well.

Equally done it with reports, and you can set the position and size of the
controls to best fill the form depending on the number of controls that are
visible. Phil

Reply With Quote
  #8  
Old   
bsn
 
Posts: n/a

Default Re: Form on the fly - VBA - 03-20-2011 , 09:10 AM



Thx - ill look into it...
Bjarne


"agiamb" <NOSPAMagiamb (AT) newsgroup (DOT) nospam> skrev i en meddelelse
news:im4sfc$lqr$1 (AT) news (DOT) eternal-september.org...
Quote:
What I would do is add an ample number of controls to the form at design
time, then at run time, set each control's source to the correct column
(or to nothing) and make it visible (or not). Seems much simpler to me
than creating a form at runtime. Especially for maintenance down the road
when client wants more features added to the form.
I have done similar with reports based on crosstab data and it works well.

--

AG
Email: npATadhdataDOTcom


"bsn" <bsnSNABELAoncableDOTdk> wrote in message
news:4d85a2a5$0$56785$edfadb0f (AT) dtext02 (DOT) news.tele.dk...

"Marshall Barton" <marshbarton (AT) wowway (DOT) com> skrev i en meddelelse
news:5joao610u2q73ihl7r913aig654cenb4ju (AT) 4ax (DOT) com...
bsn wrote:

I am making a form on the fly - it works fine, but...

In the form i have a With statement :

With frm
.Visible = False
.Caption = "Ledige tider"
.OnOpen = "Private Sub Form_Open(Cancel As Integer)" & vbCrLf &
_
" Const conInchesToTwips = 1440" & vbCrLf & _
" Dim intRight As Integer, intDown As Integer, intWidth As
Integer, intHeight As Integer" & vbCrLf & _
" DoCmd.Restore" & vbCrLf & _
" intRight = (3 * conInchesToTwips)" & vbCrLf & _
" intDown = 0" & vbCrLf & _
" intWidth = (5 * conInchesToTwips)" & vbCrLf & _
" intHeight = (5.5 * conInchesToTwips)" & vbCrLf & _
" DoCmd.MoveSize intRight, intDown, intWidth, intHeight" &
vbCrLf & _
" End Sub"
End With

The .OnOpen part do not work...
How can i write the code in Open procedure in the With statement, so it
works...???


You have to open the form's module and use the methods of
the Module object to insert the code into the module. You
would then set the OnOpen PROPERTY to:
[Event Procedure]

I must say that creating a form object and controls on the
fly is a really bad idea except when you are creating a
DESIGN TIME wizard to help yourself design forms. It can be
a whole truck load of trouble when done in a running
application.

There is almost never a valid reason to not use a prebuilt
form with precreated controls and set their properties as
needed when the form is opened.

The forms Source is a crosstabquery...
Then if there comes a colown more, it dont appear in the form...:-(
Maybee u know a better way...???
Bjarne



Reply With Quote
  #9  
Old   
bsn
 
Posts: n/a

Default Re: Form on the fly - VBA - 03-20-2011 , 09:11 AM



"Phil" <phil (AT) stantonfamily (DOT) co.uk> skrev i en meddelelse
news:im4uii$jqi$1 (AT) speranza (DOT) aioe.org...
Quote:
On 20/03/2011 12:38:00, "agiamb" wrote:
What I would do is add an ample number of controls to the form at design
time, then at run time, set each control's source to the correct column
(or to nothing) and make it visible (or not). Seems much simpler to me
than creating a form at runtime. Especially for maintenance down the road
when client wants more features added to the form.
I have done similar with reports based on crosstab data and it works
well.


Equally done it with reports, and you can set the position and size of the
controls to best fill the form depending on the number of controls that
are
visible. Phil
Thx for the add...
Bjarne

Reply With Quote
  #10  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Form on the fly - VBA - 03-20-2011 , 09:56 AM



bsn wrote:
Quote:
"Marshall Barton" <marshbarton (AT) wowway (DOT) com> skrev
bsn wrote:

I am making a form on the fly - it works fine, but...

In the form i have a With statement :

With frm
.Visible = False
.Caption = "Ledige tider"
.OnOpen = "Private Sub Form_Open(Cancel As Integer)" & vbCrLf & _
" Const conInchesToTwips = 1440" & vbCrLf & _
" Dim intRight As Integer, intDown As Integer, intWidth As
Integer, intHeight As Integer" & vbCrLf & _
" DoCmd.Restore" & vbCrLf & _
" intRight = (3 * conInchesToTwips)" & vbCrLf & _
" intDown = 0" & vbCrLf & _
" intWidth = (5 * conInchesToTwips)" & vbCrLf & _
" intHeight = (5.5 * conInchesToTwips)" & vbCrLf & _
" DoCmd.MoveSize intRight, intDown, intWidth, intHeight" &
vbCrLf & _
" End Sub"
End With

The .OnOpen part do not work...
How can i write the code in Open procedure in the With statement, so it
works...???


You have to open the form's module and use the methods of
the Module object to insert the code into the module. You
would then set the OnOpen PROPERTY to:
[Event Procedure]

I must say that creating a form object and controls on the
fly is a really bad idea except when you are creating a
DESIGN TIME wizard to help yourself design forms. It can be
a whole truck load of trouble when done in a running
application.

There is almost never a valid reason to not use a prebuilt
form with precreated controls and set their properties as
needed when the form is opened.

The forms Source is a crosstabquery...
Then if there comes a colown more, it dont appear in the form...:-(
Maybee u know a better way...???

As most anyone will tell you, the better way is to create
the form with all it's code and enough invisible text boxes
(named txtCol1, txtCol2, . . ., txtCol29) and labels (named
lblCol1, ... lblCol29) to deal with the most fields you will
ever have in the crosstab query.

Then use code in the form's Load event something like this
untested air code to configure the text boxes and column
header labels:

Dim fld As DAO.Field
Dim startpos As Long
Dim k As Integer
With Me.Recordset
startpos = Me.txtrowheader.Left _
+ Me.txtrowheader.Width
Me.InsideWidth = startpos _
+ .Fields.Count * Me.txtCol1.Width
For k = 1 To .Fields.Count - 1 'assumes one row header
field
Me("txtCol" & k).ControlSource = .Fields(k).Name
Me("lblCol" & k).Caption = .Fields(k).Name
Me("txtCol" & k).Left = startpos _
+ (k-1) * Me.txtCol1.Width
Me("lblCol" & k).Left = startpos _
+ (k-1) * Me.txtCol1.Width
Me("txtCol" & k).Visible = True
Me("lblCol" & k).Visible = True
Next k
End With

--
Marsh

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.