Condition navigating between Controls

B

Bardia

I have a form in access 2007, with several controls. I used the On Exit Event
Procedure for navigating among controls.
Example:
If Method of Payment = “Check†Then
Check No.Set Focus
End If
If Method of Payment = “Credit Card†Then
Credit Card Name.Set Focus
End If
End Sub
And so on for all controls. Form functioned well for months, however today
went wild. Navigation order does not execute Event Procedure it follows
exactly the order of TAB ORDER DIALOG BOX.
Please advice
 
S

Steve

It sounds like the On Exit event is not firing for some reason. Put these
two lines of code at the beginning of your On Exit event to test:

MsgBox "On Exit Event Just Fired"
Exit Sub

If you get the message, something else is happening.

Steve
(e-mail address removed)
 
D

Dirk Goldgar

Bardia said:
I have a form in access 2007, with several controls. I used the On Exit
Event
Procedure for navigating among controls.
Example:
If Method of Payment = “Check†Then
Check No.Set Focus
End If
If Method of Payment = “Credit Card†Then
Credit Card Name.Set Focus
End If
End Sub
And so on for all controls. Form functioned well for months, however today
went wild. Navigation order does not execute Event Procedure it follows
exactly the order of TAB ORDER DIALOG BOX.
Please advice


Did you by any chance move the database from a trusted location to an
untrusted one? If it looks lie the VBA code is just not executing, the
database may have become untrusted, and Access 2007 won't execute code in an
untrusted database.
 
R

Ruben Lopez

Bardia said:
I have a form in access 2007, with several controls. I used the On Exit
Event
Procedure for navigating among controls.
Example:
If Method of Payment = “Check†Then
Check No.Set Focus
End If
If Method of Payment = “Credit Card†Then
Credit Card Name.Set Focus
End If
End Sub
And so on for all controls. Form functioned well for months, however today
went wild. Navigation order does not execute Event Procedure it follows
exactly the order of TAB ORDER DIALOG BOX.
Please advice
 
J

Jeff Boyce

Bardia

As I recall, the OnExit event doesn't fire if you click out.

I'm thinking you'll want to try the AfterUpdate event instead.

And if your control name is, literally, "Method of Payment", then you'll
have to lend Access a hand so it knows what you're talking about. You'd
need to delimit that control name with square brackets (e.g., [Method of
Payment]) because it has embedded spaces.

Good Luck!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
J

John W. Vinson

I have a form in access 2007, with several controls. I used the On Exit Event
Procedure for navigating among controls.
Example:
If Method of Payment = “Check” Then
Check No.Set Focus
End If
If Method of Payment = “Credit Card” Then
Credit Card Name.Set Focus
End If
End Sub
And so on for all controls. Form functioned well for months, however today
went wild. Navigation order does not execute Event Procedure it follows
exactly the order of TAB ORDER DIALOG BOX.
Please advice

In addition to Steve and Dirk's concerns, one problem is that you have blanks
in your control names. Blanks are meaningful in VBA - the line

If Method of Payment = ...

is meaningless to Access, because it sees "Method" as one term, "of" as a
different unrelated term, "Payment" as yet a third. A human can see that it's
all one thing but the poor computer is pretty stupid and literal minded!

Best choice: don't put blanks in the names of things; if the textbox or field
is named MethodOfPayment or Method_Of_Payment you won't have the problem. Note
that SetFocus is one word, not two.

Alternatively, enclose your field/control names in square brackets. I'd also
suggest using the AfterUpdate event (which fires when the user has made a
change) rather than the Exit event (which fires if they just set focus to the
control and leave without doing anything), and use the Me! keyword to refer to
the current form:

If Me![Method of Payment] = “Check” Then
Me![Check No].SetFocus
ElseIf Me!Method of Payment] = “Credit Card” Then
Me![Credit Card Name].SetFocus
End If
End Sub
 
B

Bardia

Thanks, yes I copied the database file from one computer to another using
ScanDisk. But on second computer the same Access 2007 is installed. In any
case if your guess is correct how should I solve this problem?
 
D

Dirk Goldgar

Bardia said:
Thanks, yes I copied the database file from one computer to another using
ScanDisk. But on second computer the same Access 2007 is installed. In any
case if your guess is correct how should I solve this problem?

First, in Windows explorer, right-click the database file and choose
Properties from the popup menu. It may be that the file has been blocked,
as having come from another computer. If so, there will be an Unblock
button displayed on the property sheet. If you see that button, click it to
unblock the file.

If that isn't enough to fix the problem all by itself, then follow the
instructions in this article to designate the folder containing your
database as a trusted location:

http://office.microsoft.com/en-us/help/HA100319991033.aspx
Create, remove, or change a trusted location for your files
 
B

Bardia

Thank you,
Original control names are without any spaces and some are on After update .
I am really puzzled. This is a very small database and been working well
since April 2009. Another surprise is that the size of its file was 11,700
KB, now is only 2,816 KB, but when I check the total number of records they
are all there!
I even checked the database options to make sure that the box of Always use
event procedures is checked.

--
Bardia


John W. Vinson said:
I have a form in access 2007, with several controls. I used the On Exit Event
Procedure for navigating among controls.
Example:
If Method of Payment = “Check†Then
Check No.Set Focus
End If
If Method of Payment = “Credit Card†Then
Credit Card Name.Set Focus
End If
End Sub
And so on for all controls. Form functioned well for months, however today
went wild. Navigation order does not execute Event Procedure it follows
exactly the order of TAB ORDER DIALOG BOX.
Please advice

In addition to Steve and Dirk's concerns, one problem is that you have blanks
in your control names. Blanks are meaningful in VBA - the line

If Method of Payment = ...

is meaningless to Access, because it sees "Method" as one term, "of" as a
different unrelated term, "Payment" as yet a third. A human can see that it's
all one thing but the poor computer is pretty stupid and literal minded!

Best choice: don't put blanks in the names of things; if the textbox or field
is named MethodOfPayment or Method_Of_Payment you won't have the problem. Note
that SetFocus is one word, not two.

Alternatively, enclose your field/control names in square brackets. I'd also
suggest using the AfterUpdate event (which fires when the user has made a
change) rather than the Exit event (which fires if they just set focus to the
control and leave without doing anything), and use the Me! keyword to refer to
the current form:

If Me![Method of Payment] = “Check†Then
Me![Check No].SetFocus
ElseIf Me!Method of Payment] = “Credit Card†Then
Me![Credit Card Name].SetFocus
End If
End Sub
 
B

Bardia

Thank you,
Original control names are without any spaces and some are on After update .
I am really puzzled. This is a very small database and been working well
since April 2009. Another surprise is that the size of its file was 11,700
KB, now is only 2,816 KB, but when I check the total number of records they
are all there!
I even checked the database options to make sure that the box of Always use
event procedures is checked.

--
Bardia


Jeff Boyce said:
Bardia

As I recall, the OnExit event doesn't fire if you click out.

I'm thinking you'll want to try the AfterUpdate event instead.

And if your control name is, literally, "Method of Payment", then you'll
have to lend Access a hand so it knows what you're talking about. You'd
need to delimit that control name with square brackets (e.g., [Method of
Payment]) because it has embedded spaces.

Good Luck!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

Bardia said:
I have a form in access 2007, with several controls. I used the On Exit
Event
Procedure for navigating among controls.
Example:
If Method of Payment = "Check" Then
Check No.Set Focus
End If
If Method of Payment = "Credit Card" Then
Credit Card Name.Set Focus
End If
End Sub
And so on for all controls. Form functioned well for months, however today
went wild. Navigation order does not execute Event Procedure it follows
exactly the order of TAB ORDER DIALOG BOX.
Please advice


.
 
J

John W. Vinson

Thank you,
Original control names are without any spaces and some are on After update .
I am really puzzled. This is a very small database and been working well
since April 2009. Another surprise is that the size of its file was 11,700
KB, now is only 2,816 KB, but when I check the total number of records they
are all there!
I even checked the database options to make sure that the box of Always use
event procedures is checked.


Hope you have a backup. :-{(

It certainly sounds as if something is corrupt. Is the code you posted in fact
the same as the code actually in use in the database? I cannot see how it
could EVER have worked, at least not as it was posted.
 
B

Bardia

I am great full, problem solved.
--
Bardia


Dirk Goldgar said:
First, in Windows explorer, right-click the database file and choose
Properties from the popup menu. It may be that the file has been blocked,
as having come from another computer. If so, there will be an Unblock
button displayed on the property sheet. If you see that button, click it to
unblock the file.

If that isn't enough to fix the problem all by itself, then follow the
instructions in this article to designate the folder containing your
database as a trusted location:

http://office.microsoft.com/en-us/help/HA100319991033.aspx
Create, remove, or change a trusted location for your files

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 

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