Keep my Form Open

B

Bob Vance

I have a form that selects my client by Combo Box, but after I select my
clients and open the report my form close's each time, I have tried to stop
it from closing, where do I look to see what is closing my form after report
is activated
 
J

John W. Vinson

I have a form that selects my client by Combo Box, but after I select my
clients and open the report my form close's each time, I have tried to stop
it from closing, where do I look to see what is closing my form after report
is activated

In the code which opens the report (probably the combo box's AfterUpdate
event). Care to post the code?
 
B

Bob Vance

John W. Vinson said:
In the code which opens the report (probably the combo box's AfterUpdate
event). Care to post the code?
Thanks John I added a code to the report so when It closed it opened my
form, Just trying now to set focus to cbOwnersName on my form so as when I
click the preview control the focus shifts to cbOwnersName
Regards Bob
Private Sub Report_Deactivate()
DoCmd.Close
DoCmd.OpenForm "frmBillStatement", acNormal, , , , acDialog,
"OwnerStatement"

End Sub
Private Sub cmdStatementOld_Click()


Dim savRepName As String, savFileName As String

Select Case Me.OpenArgs

Case "OwnerStatement"

If IsNull(cbOwnerName.value) = True Or cbOwnerName.value =
vbNullString Then
MsgBox "Please make a Seletion!", vbApplicationModal +
vbInformation + vbOKOnly
Exit Sub
End If

Me.Visible = False
DoCmd.OpenReport "rptOwnerPaymentMethodShort", acPreview

Me.cbOwnerName.SetFocus
Case "MonthlyPaid"


savRepName = "rptGenericReport"

savFileName = "Montly Paid.rtf"
Me.Form.Visible = False
DoCmd.OpenReport savRepName, acViewPreview, , , , Me.OpenArgs

Case "OwnerDue"

Me.Visible = False
DoCmd.OpenReport "rptGenericReport", acViewPreview, , , ,
"OwnerDue"
DoCmd.Close acForm, Me.Name

Me.cbOwnerName.SetFocus
Case "OwnerPaymentMethod"

If IsNull(cbOwnerName.value) = True Or cbOwnerName.value =
vbNullString Then
MsgBox "Please make a Selection!", vbApplicationModal +
vbInformation + vbOKOnly
Exit Sub
End If

Me.Visible = False
DoCmd.OpenReport "rptGenericReport", acViewPreview, , , ,
"OwnerPaymentMethodShort"
DoCmd.Close acForm, Me.Name
Me.cbOwnerName.SetFocus
Case "PaymentMethod"

Dim nDateDiff As Integer, nSign As Integer
nDateDiff = DateDiff("d", CDate(tbDateFrom.value),
CDate(tbDateTo.value))
nSign = Sgn(nDateDiff)

If nSign = -1 Or nSign = 0 Then
MsgBox "Please Select Date In Proper Range.",
vbApplicationModal + vbExclamation + vbOKOnly
cmdCalenderTo.SetFocus
Exit Sub
End If

Me.Visible = False
DoCmd.OpenReport "rptGenericReport", acViewPreview, , , ,
"PaymentMethod"
DoCmd.Close acForm, Me.Name
Me.cbOwnerName.SetFocus
Case "PrintInvoiceBatch"
If IsNull(tbDateFrom.value) Or tbDateFrom.value = "" Or
IsNull(tbDateTo.value) Or tbDateTo.value = "" Then
MsgBox "Please Enter the Begining Date and End Date.",
vbApplicationModal + vbInformation + vbOKOnly
Exit Sub
End If
Me.Visible = False
DoCmd.OpenReport "rptInvoiceBatch", acViewPreview, , , ,
"PrintInvoiceBatch"

Case "PrintStatementBatch"

If IsNull(tbDateFrom.value) Or tbDateFrom.value = "" Or
IsNull(tbDateTo.value) Or tbDateTo.value = "" Then
MsgBox "Please Enter the Begining Date and End Date.",
vbApplicationModal + vbInformation + vbOKOnly
Exit Sub
End If
Me.Visible = False
DoCmd.OpenReport "rptOwnerPaymentMethodBatch", acViewPreview, , , ,
"PrintStatementBatch"

End Select


End Sub

Private Sub cmdStatementOld_GotFocus()
cbOwnerName.SetFocus
End Sub

Private Sub cmdStatementOld_KeyUp(KeyCode As Integer, Shift As Integer)
Me.cbOwnerName.SetFocus
End Sub
 
J

John Spencer

Try changing the line
DoCmd.Close
so you specify the report by name. If you don't specify the item you want to
close then whichever object (form, report, query, table, etc.)has the focus at
the time the Close is executed will be what gets closed. I'm not sure where
the focus is when you are in the Reports Deactivate event, but it very well
may not be on the report at that point.

DoCmd.Close acReport, Me.Name

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
B

Bob Vance

Thanks John, That did the trick!

John Spencer said:
Try changing the line
DoCmd.Close
so you specify the report by name. If you don't specify the item you want
to close then whichever object (form, report, query, table, etc.)has the
focus at the time the Close is executed will be what gets closed. I'm not
sure where the focus is when you are in the Reports Deactivate event, but
it very well may not be on the report at that point.

DoCmd.Close acReport, Me.Name

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
A

Armen Stein

Try changing the line
DoCmd.Close
so you specify the report by name. If you don't specify the item you want to
close then whichever object (form, report, query, table, etc.)has the focus at
the time the Close is executed will be what gets closed. I'm not sure where
the focus is when you are in the Reports Deactivate event, but it very well
may not be on the report at that point.

DoCmd.Close acReport, Me.Name

And it's not always the form with the *focus*, but the "active"
object. Years ago we discovered that a timer on a hidden "sentinel"
form would make that form "active" momentarily when it fired. When
the DoCmd.Close statement ran elsewhere, the hidden sentinel form
would be closed instead. That was a tough one to debug, because it
happened so intermittently!

The explicit parameters for DoCmd.Close should *always* be used. Trust
me.

Armen Stein
Microsoft Access MVP
www.JStreetTech.com
 
T

Tom Wickerath

Hi Bob,
I have a form that selects my client by Combo Box, but after I select my
clients and open the report my form close's each time, I have tried to stop
it from closing, where do I look to see what is closing my form after report
is activated

The code you posted in response to John's invitation includes several
occurances of
Me.Visible = False (depending on the branch taken via a Select Case
statement). Thus, it appears to me that this form is not being closed, it is
simply being hidden.
Thanks John I added a code to the report so when It closed it opened my
form, ...

You can use DoCmd.OpenForm to display a form that was open but in hidden
mode.
Just trying now to set focus to cbOwnersName on my form so as when I
click the preview control the focus shifts to cbOwnersName

Create a new Form_Activate procedure, adding this code:

Me.cbOwnersName.SetFocus

Form_Activate should work if the form is being opened for the first time, or
re-opened from hidden mode.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top