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
  #11  
Old   
bsn
 
Posts: n/a

Default Re: Form on the fly - VBA - 03-20-2011 , 06:08 PM






"Marshall Barton" <marshbarton (AT) wowway (DOT) com> skrev i en meddelelse
news:647co6hhg7kmen1atq30rft8gppj6o7ea4 (AT) 4ax (DOT) com...
Quote:
bsn wrote:
"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
Thx for answer...
I was renaming my controls...
Here is what get the job done...
Me.Controls("txt5").ColumnHidden = True
And then later in an If sentence
Me.Controls("txt5").ColumnHidden = False
Bjarne

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.