Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subform OnCurrent Event Processes Before Form and Subform Are Visible

Status
Not open for further replies.

HardingR2000

Programmer
Oct 6, 2008
40
0
0
US
I have a form which contains a subform. The OnCurrent event in the subform checks a date field on the subform and depending on the value issues a MsgBox message. The problem is that the subform's OnCurrent event processes before the form and subform are visible, therefore the messages pop up without the data on the subform visible for reference purposes. It is very unfriendly.

I have tried a coding technique to logically bypass the subform's OnCurrent event until after everything is visible, but I cannot find an event in the form or subforms that fires once the form and/or subforms are visible.

Is it possible to delay the processing in the subform's OnCurrent event until after everything is visible?
 
I use this code to check if a form is a subform
Code:
Public Function isSubForm(frm As Access.Form) As Boolean
 On Error GoTo errLbl:
  isSubForm = True
  Dim parnt As Access.Form
  Set parnt = frm.Parent
  Exit Function
errLbl:
  If Not Err.Number = 2452 Then
    'your error handling
  End If
  isSubForm = False
End Function

since the subform loads before the main form then I beleive that this will work. Put this in the oncurrent event and if it returns true then execute your code
 
I guess that only solves part of the problem; suppressing the message before everything is loaded. However, once the main form is loaded you then need to call the on current event of the sub form. You then could actually call the subforms event from the main form once everything is loaded:

When you first open a form, the following events occur in this order:

Open ? Load ? Resize ? Activate ? Current

So from the main form in the load event you then could do something like

me.subformControlName.form.Form_Current
 
I apologize, I actually tested this and it does not work. The code still runs before the form is visible. Let me think on this one.
 
OK I got this to work, but there is probably a simpler way.

subform code make the current event public, and add a form level variable:
Code:
Public formVisible As Boolean

Public Sub Form_Current()
  'bypass your code until everything is visible
  If formVisible Then
      'do your code
  End If
End Sub

main form code where the subform control is called "frmTest":
Code:
Private Sub Form_Activate()
  'set the subform public variable
  Me.frmTest.Form.formVisible = True
  'ensure the subform is visible
  Me.frmTest.Form.Visible = True
  'ensure main form visibl
  Me.Visible = True
  'fire the subform on current event now that the main and sub are visible
  Me.frmTest.Form.Form_Current
End Sub

 
MajP,
Thank you for your help. I will give this a try.

Randy
 
Hi Randy,

Another approach might be to check, in your subform, if the recordset for the subform is at EOF (End of File). If so, the just ignore the date test.

Another thought might be to check the record key or some other required field and if null, then igore date test.

Good Luck,
Hap...


Access Developer [pc] Access based Accounting Solutions - with free source code
Access Consultants forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top