Lost Focus??

  • Thread starter Thread starter Pam
  • Start date Start date
P

Pam

Hi,
I have several date fields on a form that I want to tab thru. After
entering the date in the first and tabbing to the second, it seems as though
the whole form looses focus. The blue bar at the top dims until I press
enter and then I can enter the date in the second field. I checked tab
order and it's okay and tab stop is yes on property sheet.
Can someone please tell me what I'm doing wrong?
Thanks in advance,
Pam
 
Pam said:
Hi,
I have several date fields on a form that I want to tab thru. After
entering the date in the first and tabbing to the second, it seems as
though the whole form looses focus. The blue bar at the top dims
until I press enter and then I can enter the date in the second
field. I checked tab order and it's okay and tab stop is yes on
property sheet.
Can someone please tell me what I'm doing wrong?

First check the tab order of the controls on the form. You can do that
by right-clicking on the detail section (in design view) and choosing
Tab Order... from the context menu. Make sure that the tab order is
going from the first fields to the second field, as you expect. If not,
change the tab order using the dialog you're looking at.

Second, check to see if there is any code or macro being executed in the
Exit or Lost Focus events of the first text box. If so, maybe that code
or macro is doing something that changes the focus.
 
Dirk,
Thanks for replying. I checked the tab order and it is in order as needed.
I do have code to run a report from the first field on exit. I've included
it below and hope you won't mind looking over it to see if anything stands
out that may be causing the problem.

Private Sub Incoming_Exit(Cancel As Integer)
On Error GoTo Err_Incoming_Exit

If [Forms]![f*GeneralInformationWITHQUOTE]![CustomerName] = "Lyondell" Then
DoCmd.OpenReport "rRMABatchRegularLyondell", , , "JobNumber=" &
[Forms]![f*GeneralInformationWITHQUOTE]![JobNumber]
Else
DoCmd.OpenReport "rRMABatchRegular", , , "JobNumber=" &
[Forms]![f*GeneralInformationWITHQUOTE]![JobNumber]

End If

Exit_Incoming_Exit:
Exit Sub

Err_Incoming_Exit:
MsgBox Err.Description
Resume Exit_Incoming_Exit
End Sub

Your help is appreciated!
Thanks,
Pam
 
Pam said:
Dirk,
Thanks for replying. I checked the tab order and it is in order as
needed. I do have code to run a report from the first field on exit.
I've included it below and hope you won't mind looking over it to see
if anything stands out that may be causing the problem.

Private Sub Incoming_Exit(Cancel As Integer)
On Error GoTo Err_Incoming_Exit

If [Forms]![f*GeneralInformationWITHQUOTE]![CustomerName] =
"Lyondell" Then DoCmd.OpenReport "rRMABatchRegularLyondell", , ,
"JobNumber=" & [Forms]![f*GeneralInformationWITHQUOTE]![JobNumber]
Else
DoCmd.OpenReport "rRMABatchRegular", , , "JobNumber=" &
[Forms]![f*GeneralInformationWITHQUOTE]![JobNumber]

End If

Exit_Incoming_Exit:
Exit Sub

Err_Incoming_Exit:
MsgBox Err.Description
Resume Exit_Incoming_Exit
End Sub

The form will naturally lose focus while the report is being generated.
Since you're sending the report directly to the printer, I'd expect the
form to regain the focus after the report has been generated and queued
for printing. Does that happen? If not, is there any code in the
report that is displaying a dialog or otherwise shifting the focus?
 
Dirk,
After entering the date in the first field, the report starts printing and I
like to tab to the next field, but have to press enter to get the focus back
to the whole form (the blue bar at top dims). I'm not sure what you mean
about the report displaying a dialog or shifting focus. I'm not sure this
explanation will help.

Pam


Dirk Goldgar said:
Pam said:
Dirk,
Thanks for replying. I checked the tab order and it is in order as
needed. I do have code to run a report from the first field on exit.
I've included it below and hope you won't mind looking over it to see
if anything stands out that may be causing the problem.

Private Sub Incoming_Exit(Cancel As Integer)
On Error GoTo Err_Incoming_Exit

If [Forms]![f*GeneralInformationWITHQUOTE]![CustomerName] =
"Lyondell" Then DoCmd.OpenReport "rRMABatchRegularLyondell", , ,
"JobNumber=" & [Forms]![f*GeneralInformationWITHQUOTE]![JobNumber]
Else
DoCmd.OpenReport "rRMABatchRegular", , , "JobNumber=" &
[Forms]![f*GeneralInformationWITHQUOTE]![JobNumber]

End If

Exit_Incoming_Exit:
Exit Sub

Err_Incoming_Exit:
MsgBox Err.Description
Resume Exit_Incoming_Exit
End Sub

The form will naturally lose focus while the report is being generated.
Since you're sending the report directly to the printer, I'd expect the
form to regain the focus after the report has been generated and queued
for printing. Does that happen? If not, is there any code in the
report that is displaying a dialog or otherwise shifting the focus?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Pam said:
Dirk,
After entering the date in the first field, the report starts
printing and I like to tab to the next field, but have to press enter
to get the focus back to the whole form (the blue bar at top dims).
I'm not sure what you mean about the report displaying a dialog or
shifting focus. I'm not sure this explanation will help.

I'm not sure, but I *think* what's happening is normal -- the form
doesn't get the focus back until Access is done generating the report.
You could try modifying your code in an attempt to set the focus right
back to the form, like this:

'----- start of revised code -----
Private Sub Incoming_Exit(Cancel As Integer)
On Error GoTo Err_Incoming_Exit

Dim strReportName As String

If Me!CustomerName = "Lyondell" Then
strReportName = "rRMABatchRegularLyondell"
Else
strReportName = "rRMABatchRegular"
End If

DoCmd.OpenReport strReportName, _
WhereCondition:="JobNumber=" & Me!JobNumber

DoCmd.SelectObject acForm, Me.Name

Exit_Incoming_Exit:
Exit Sub

Err_Incoming_Exit:
MsgBox Err.Description
Resume Exit_Incoming_Exit
End Sub
'----- end of revised code -----

Note that I've assumed that the form name
"f*GeneralInformationWITHQUOTE" in your original code is the name of the
form on which this code is running. I used that assumption to simplify
the code somewhat, but if it's wrong, we'll have to go back to the full
"Forms!<form name>!<control name>" notation.

The "DoCmd.SelectObject" line in the above code is intended to get the
focus back onto this form as soon as possible; however, I have my
doubts as to whether it will work.

If it doesn't, I can think of two possible workarounds, but they are
both rather elaborate, and I'm not sure it's worth it. For my own
applications, I wouldn't normally use the Exit event of a text box to
open a report, as I feel that doesn't give the user a chance to correct
an incorrect entry. But if you really want the focus to get back to the
form immediately, and the above code revision doesn't do it, let me know
and we can try one of the alternatives I have in mind.
 
Dirk,

Thanks for your help, but you were right in thinking the SelectObject may
not work. If the other alternatives are are elaborate, I agree it's not
worth it for what I'm trying to do. Thanks again for your time and help.
Pam
 
Pam said:
Dirk,

Thanks for your help, but you were right in thinking the SelectObject
may not work. If the other alternatives are are elaborate, I agree
it's not worth it for what I'm trying to do. Thanks again for your
time and help. Pam

I tried one of my "other alternatives" and it didn't work. I think your
problem is coming from the display of the modal "Printing..." dialog,
and about the only alternative I can find for that is this:

http://www.mvps.org/access/api/api0037.htm

.... which is undeniably elaborate. It's possible you can suppress this
dialog by modifying the registry, but if so, I don't know the correct
key offhand.
 
Back
Top