Hi all,

I'm trying to programmatically create a form, add a command button, and assign an event procedure for the button. I'm running into a problem with adding the event procedure.

Here is the code I currently have:

VB Code:
  1. Dim frmWarning As Form
  2.     Dim btnOK As CommandButton
  3.    
  4.     Set frmWarning = CreateForm
  5.     With frmWarning
  6.         .Caption = "Warning"
  7.         .AllowFormView = True
  8.         .PopUp = True
  9.         .ScrollBars = 0 'no scrollbars
  10.         .RecordSelectors = False
  11.         .NavigationButtons = False
  12.         .DividingLines = False
  13.         .Modal = True
  14.         .Width = 4000
  15.         .GridX = 40
  16.         .GridY = 40
  17.         .Moveable = True
  18.         .AutoCenter = True
  19.         .CloseButton = False
  20.         .ControlBox = False
  21.     End With
  22.    
  23.     Set btnOK = CreateControl(frmWarning.Name, acCommandButton, acDetail, , , 1500, 2700, 950, 450)
  24.     btnOK.Caption = "OK"
  25.     btnOK.OnClick = "[Event Procedure]"     'Here is the problem
  26.            
  27.     DoCmd.OpenForm frmWarning.Name, acNormal
  28.    
  29.     DoCmd.Restore
  30.     DoCmd.MoveSize 6000, 4000, 5500, 1800
  31.    
  32.     'frmWarning.SetFocus
  33.     'frmWarning.Move 400, 400, 4000, 4000

I read in msdn that I should have "[Event Procedure]" as the OnClick property, but I can't figure out how to tell it which function to run.

Does anyone have any ideas on this?

Thanks,
Ranthalion