I've lost my focus for forms

  • Thread starter Thread starter Doug
  • Start date Start date
D

Doug

Access 2000:

This is OpenEvent for my MainForm. If condition below is met,
I want to see ExpiryDatesForm and when I close ExpiryDatesForm,
then MainForm can have the Focus. At present, MainForm keeps
the focus and ExpiryDatesForm is minimized. Can anyone help?

I'm slipping a second question in here.
When I go from FormView to DesignView and back to FormView,
Access has reset my Static variable. Is this normal or did I
use the Static variable incorrectly?

TIA
Doug

Private Sub Form_Open()
Dim intPlates As Integer
Dim strWHERE As String

Static Opened As Boolean

strWHERE = "Plate_expire < #" & LastOfMonth & "#"
intPlates = DCount("Car_ID", "tblCarDetails", strWHERE)

If (intPlates > 0) _
And (Not Opened) Then
DoCmd.OpenForm "ExpiryDates"
Forms![ExpiryDates].SetFocus
Opened = True
End If

End Sub
 
Doug,

Not sure why your form is opening minimized. Have you checked for any code
of yours that will do this? Anyway, I suppose you could issue the following
commands to automatically resore the window:

DoCmd.SelectObject acForm, "ExpiryDatesForm", False
DoCmd.Restore

With regard you your local, static variable, switching between Form View and
Design does and will reinit the variable. If I were you, I'd use a function
to check if a form is open. Check out this article on the Access Web:
http://www.mvps.org/access/forms/frm0002.htm

Then your code would look like the following. No need to track a form's or
report's open status using variables.

If intPlates > 0 And Not fIsLoaded("ExpiryDatesForm") Then
DoCmd.OpenForm "ExpiryDates"
Forms![ExpiryDates].SetFocus
DoCmd.Restore 'If necessary
End If

Hope this helps.

Reid
 
Back
Top