odd focus behaviour

T

TonyT

I have a form that has a combobox that allows the user to select an existing
customer. The afterupdate code sets the rowsource for a second combobox,
makes it visible & sets the focus to said 2nd combobox, BUT, without an error
the focus disappears from any control on the form (the only open form) &
pressing Tab elicits just a 'donk' error sound & focus remains nowhere to be
seen.

Stepping thru the code it works just fine, only at runtime does it fail,
seemingly trying to set the focus whilst requerying or making the second
combobox visible. This works fine on many other OS & office combinations, but
failed today on install on a vista home + office 2007 pro pc, all references
are in place, but I'm wondering if one is corrupt, anyone know which dll
affects focus?
 
D

Dirk Goldgar

TonyT said:
I have a form that has a combobox that allows the user to select an
existing
customer. The afterupdate code sets the rowsource for a second combobox,
makes it visible & sets the focus to said 2nd combobox, BUT, without an
error
the focus disappears from any control on the form (the only open form) &
pressing Tab elicits just a 'donk' error sound & focus remains nowhere to
be
seen.

Stepping thru the code it works just fine, only at runtime does it fail,
seemingly trying to set the focus whilst requerying or making the second
combobox visible. This works fine on many other OS & office combinations,
but
failed today on install on a vista home + office 2007 pro pc, all
references
are in place, but I'm wondering if one is corrupt, anyone know which dll
affects focus?


Would you mind posting the code involved? Maybe there's something there
that explains what's happening. The only thing I can think of is a hidden
error dialog of some sort.
 
T

TonyT

Dirk Goldgar said:
Would you mind posting the code involved? Maybe there's something there
that explains what's happening. The only thing I can think of is a hidden
error dialog of some sort.

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

(please reply to the newsgroup)
code is;

Private Sub cboSelCust_AfterUpdate()

'if previous customer is selected
If Nz(Me.cboSelCust, "") <> "" Then
'do credit checks now
If Not fncCred(Me.cboSelCust, 0.0001) Then
Me.cmdClose.SetFocus
Exit Sub
End If
'select record for chosen customer
Me.DataEntry = False
Me.AllowAdditions = False
Me.RecordSource = "SELECT * FROM CustTbl WHERE CustID = " &
Me.cboSelCust & ""
'if they have previous machine history display previous selection box
If DCount("*", "JobDatestbl", "CustID = " & Me.txtCustID & "") >= 1
Then
Me.cboSelPrevMach.RowSource = "SELECT * FROM qryMachOwned WHERE
CustID = " & Me.txtCustID & ""
Me.cboSelPrevMach.Requery
Me.cboSelPrevMach.Visible = True
Me.lblSelPrev.Visible = True
Me.boxSelPrev.Visible = True
Me.cboSelPrevMach.SetFocus
'else hide previous selection box
Else:
Me.cboSelPrevMach.Visible = False
Me.lblSelPrev.Visible = False
Me.boxSelPrev.Visible = False
Me.cboSelMake.SetFocus
End If
'else keep as dataentry
Else:
'1st undo any changes that might have been made to a previously
selected customer record
If Me.Dirty Then
Me.Undo
End If
Me.DataEntry = True
Me.AllowAdditions = True
Me.txtSurname.SetFocus
End If

fncCred function checks for outstanding payments, only error coding returns
boolean false, no suppression / resume next coding anywhere.
 
D

Dirk Goldgar

TonyT said:
code is;

Private Sub cboSelCust_AfterUpdate()

'if previous customer is selected
If Nz(Me.cboSelCust, "") <> "" Then
'do credit checks now
If Not fncCred(Me.cboSelCust, 0.0001) Then
Me.cmdClose.SetFocus
Exit Sub
End If
'select record for chosen customer
Me.DataEntry = False
Me.AllowAdditions = False
Me.RecordSource = "SELECT * FROM CustTbl WHERE CustID = " &
Me.cboSelCust & ""
'if they have previous machine history display previous selection
box
If DCount("*", "JobDatestbl", "CustID = " & Me.txtCustID & "") >= 1
Then
Me.cboSelPrevMach.RowSource = "SELECT * FROM qryMachOwned WHERE
CustID = " & Me.txtCustID & ""
Me.cboSelPrevMach.Requery
Me.cboSelPrevMach.Visible = True
Me.lblSelPrev.Visible = True
Me.boxSelPrev.Visible = True
Me.cboSelPrevMach.SetFocus
'else hide previous selection box
Else:
Me.cboSelPrevMach.Visible = False
Me.lblSelPrev.Visible = False
Me.boxSelPrev.Visible = False
Me.cboSelMake.SetFocus
End If
'else keep as dataentry
Else:
'1st undo any changes that might have been made to a previously
selected customer record
If Me.Dirty Then
Me.Undo
End If
Me.DataEntry = True
Me.AllowAdditions = True
Me.txtSurname.SetFocus
End If

fncCred function checks for outstanding payments, only error coding
returns
boolean false, no suppression / resume next coding anywhere.


Hmm. While there are a couple of minor quirks in your code (e.g., no need
to requery a combo box after you've set its RowSource), I don't think those
are the source of your problem. I wonder if the problem could be caused by
your setting the form's RecordSource. That is going to potentially cause a
number of events to fire, I *think* before this event procedure completes.
Do you have code in the form's Current event, or the GotFocus event of some
form control that may get the focus when the form is requeried?

You say that stepping through the code works fine, so maybe there's a timing
issue. When you do step through the code, do you find that the code goes
through some other event procedures besides this one?
 
T

TonyT

Hi Dirk,

the requery was left over before the rowsource was changed & has now been
edited out, there is no code on_Current for the form or any focus change
events to any controls, just what I posted & the fairly convoluted credit
check function that goes off and calculates 30/60/90+ day credit totals,
checks account status etc etc, but either returns true (with msgbox's) or
false, but works just fine on many other pc's. I was under the impression
that the function would have to return true/false before the code could
evaluate it & must therefore have finished executing well before any of the
focus change options?
 
D

Dirk Goldgar

TonyT said:
Hi Dirk,

the requery was left over before the rowsource was changed & has now been
edited out, there is no code on_Current for the form or any focus change
events to any controls, just what I posted & the fairly convoluted credit
check function that goes off and calculates 30/60/90+ day credit totals,
checks account status etc etc, but either returns true (with msgbox's) or
false, but works just fine on many other pc's. I was under the impression
that the function would have to return true/false before the code could
evaluate it & must therefore have finished executing well before any of
the
focus change options?


The function must have finished before its return value can be processed by
the If statement, so that's *probably* not an issue. It is *possible* that
the function could have started some asynchronous action that might not be
complete yet; however, only you can say whether that's the case. Does the
function open any forms in other than dialog mode? I'm leaning away from
this explanation now, but can't rule it out.

Is this failing on only one computer? Have you checked the references on
that computer, to see if any is marked MISSING? You mentioned that it's
failing on a PC with Office 2007 installed. If you're running this with
Access 2007, is the database installed in a trusted location, or have you
explicitly set the trust settings to allow VBA code to run?
 
T

TonyT

Dirk Goldgar said:
The function must have finished before its return value can be processed by
the If statement, so that's *probably* not an issue. It is *possible* that
the function could have started some asynchronous action that might not be
complete yet; however, only you can say whether that's the case. Does the
function open any forms in other than dialog mode? I'm leaning away from
this explanation now, but can't rule it out.

Is this failing on only one computer? Have you checked the references on
that computer, to see if any is marked MISSING? You mentioned that it's
failing on a PC with Office 2007 installed. If you're running this with
Access 2007, is the database installed in a trusted location, or have you
explicitly set the trust settings to allow VBA code to run?

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

(please reply to the newsgroup)

No other forms are opened by the function & I'm happy no other code is
trying to run asynchronously.

Yes this is only happening on one pc, which was missing msowc.dll, but
compiles fine after adding it to the OFFICE 12 folder & registering it.

The database is in a trusted location & it's set to run all vba.

It sounds like it's doing the same thing in another (unrelated) form (that
again has been working fine on other pc's), hence my wondering about
references originally, perhaps I should start replacing them one-by-one?
 
D

Dirk Goldgar

TonyT said:
No other forms are opened by the function & I'm happy no other code is
trying to run asynchronously.

Yes this is only happening on one pc, which was missing msowc.dll, but
compiles fine after adding it to the OFFICE 12 folder & registering it.

The database is in a trusted location & it's set to run all vba.

It sounds like it's doing the same thing in another (unrelated) form (that
again has been working fine on other pc's), hence my wondering about
references originally, perhaps I should start replacing them one-by-one?


If the references are all fixed now, you might try decompiling and
recompiling the project. Failing that, you might create a new database, set
the references in it, then import all objects from the original database
(ideally, the decompiled version).

If that doesn't work, you might try exporting the failing forms as text
files using the barely-documented Application.SaveAsText method, then
deleting the forms and importing them from the text files using the
Application.LoadFromText method.

If that doesn't work, I'm coming to the end of things to suggest, at least
without having the database itself to work with.
 

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