![]() | |
#11
| |||
| |||
|
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |