|
-
Mar 23rd, 2006, 10:29 AM
#4
Thread Starter
Member
Re: Access vba: how to programmatically create form with onclick event
OK,
I've been working on this and still haven't really come up with any progress. I've read about the withevents keyword, and found some examples of its use with VBA, and I thought I understood how it should work. I have a form with a commandButton on it. The commandButton has an event procedure which should create a new form and generate a commandbutton on the new form. The second form is generated just fine, but it doesn't respond to any of the events I try to define for it. Here is the current version of my code:
Code:
Option Compare Database
Option Explicit
Public WithEvents frmWarning As Form
Public WithEvents btnOK As CommandButton
Public Sub btnOK_Click()
MsgBox "hello there"
End Sub
Public Sub frmWarning_Load()
MsgBox "load"
End Sub
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
Set frmWarning = CreateForm
With frmWarning
.Caption = "Warning"
.AllowFormView = True
.PopUp = True
.ScrollBars = 0 'no scrollbars
.RecordSelectors = False
.NavigationButtons = False
.DividingLines = False
.Modal = True
.Width = 4000
.GridX = 40
.GridY = 40
.Moveable = True
.AutoCenter = True
.CloseButton = False
.ControlBox = False
.OnLoad = "[Event Procedure]"
End With
Set btnOK = CreateControl(frmWarning.Name, acCommandButton, acDetail, , , 1500, 2700, 950, 450)
btnOK.Caption = "OK"
btnOK.OnClick = "[Event Procedure]"
DoCmd.OpenForm frmWarning.Name, acNormal
DoCmd.Restore
DoCmd.MoveSize 6000, 4000, 5500, 1800
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox (Err.Number & ": " & Err.Description)
GoTo Exit_Command0_Click
End Sub
This is contained the module connected to the main form. It is called Form_Form1. I did not create a class module for the second form. As far as I have learned, the above code should work fine, but the events are never fired when the second form load, nor when I press the command button on the second form (btnOK). Any ideas or advice on what I need to do to get the events to fire correctly, or to be able to handle them?
Thanks,
Ranthalion
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|