473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

a2k - weird code behaviour I can't explain...

Here's the code;
Private Sub txtTeachName_LostFocus()

If IsNull(Me.txtName) Then 'line A
Forms!frmMainform!frmSubform.Locked = True
GoTo Exit_txtName
Else 'line B
Forms!frmMainform!frmSubform.Locked = False 'line C
If IsEmpty(oldName) Then
oldName = Me.Name
GoTo Exit_txtName
End If
End If

Exit_txtName:
Exit Sub

End Sub
If txtName isn't a null then I see the code jump to Else (the line marked B)
and then jump back to the first If - i.e it doesn't run the code after the
Else statement.
This happens around 25 times then finally the pointer moves on and finally
reaches the Exit Sub at the end.
However it does NOT exit the code as I would expect but instead moves to the
line marked C. It then moves to A. This second loop keeps going for quite
a while and I'm still stepping through it as I write.

I really have no idea why this is happening - I can only assume it's caused
by some weird combination of events, yet I am stepping through everything
and only the lostfocus event is firing.
Any ideas?

thanks
Martin
Nov 12 '05 #1
8 1418
How many lines on your subform?
"Deano" <de*********@hotmail.com> wrote in message
news:Hn****************@wards.force9.net...
Here's the code;
Private Sub txtTeachName_LostFocus()

If IsNull(Me.txtName) Then 'line A
Forms!frmMainform!frmSubform.Locked = True
GoTo Exit_txtName
Else 'line B
Forms!frmMainform!frmSubform.Locked = False 'line C
If IsEmpty(oldName) Then
oldName = Me.Name
GoTo Exit_txtName
End If
End If

Exit_txtName:
Exit Sub

End Sub
If txtName isn't a null then I see the code jump to Else (the line marked B) and then jump back to the first If - i.e it doesn't run the code after the
Else statement.
This happens around 25 times then finally the pointer moves on and finally
reaches the Exit Sub at the end.
However it does NOT exit the code as I would expect but instead moves to the line marked C. It then moves to A. This second loop keeps going for quite a while and I'm still stepping through it as I write.

I really have no idea why this is happening - I can only assume it's caused by some weird combination of events, yet I am stepping through everything
and only the lostfocus event is firing.
Any ideas?

thanks
Martin

Nov 12 '05 #2
Phil Stanton wrote:
How many lines on your subform?
46 filtered records.


"Deano" <de*********@hotmail.com> wrote in message
news:Hn****************@wards.force9.net...
Here's the code;
Private Sub txtTeachName_LostFocus()

If IsNull(Me.txtName) Then 'line A
Forms!frmMainform!frmSubform.Locked = True
GoTo Exit_txtName
Else 'line B
Forms!frmMainform!frmSubform.Locked = False 'line C
If IsEmpty(oldName) Then
oldName = Me.Name
GoTo Exit_txtName
End If
End If

Exit_txtName:
Exit Sub

End Sub
If txtName isn't a null then I see the code jump to Else (the line
marked B) and then jump back to the first If - i.e it doesn't run
the code after the Else statement.
This happens around 25 times then finally the pointer moves on and
finally reaches the Exit Sub at the end.
However it does NOT exit the code as I would expect but instead
moves to the line marked C. It then moves to A. This second loop
keeps going for quite a while and I'm still stepping through it as I
write.

I really have no idea why this is happening - I can only assume it's
caused by some weird combination of events, yet I am stepping
through everything and only the lostfocus event is firing.
Any ideas?

thanks
Martin


Nov 12 '05 #3
Can't help then I was wondering if it was requerying the subform once for
each record, but no

Sorry

"Deano" <de*********@hotmail.com> wrote in message
news:EV*****************@wards.force9.net...
Phil Stanton wrote:
How many lines on your subform?


46 filtered records.


"Deano" <de*********@hotmail.com> wrote in message
news:Hn****************@wards.force9.net...
Here's the code;
Private Sub txtTeachName_LostFocus()

If IsNull(Me.txtName) Then 'line A
Forms!frmMainform!frmSubform.Locked = True
GoTo Exit_txtName
Else 'line B
Forms!frmMainform!frmSubform.Locked = False 'line C
If IsEmpty(oldName) Then
oldName = Me.Name
GoTo Exit_txtName
End If
End If

Exit_txtName:
Exit Sub

End Sub
If txtName isn't a null then I see the code jump to Else (the line
marked B) and then jump back to the first If - i.e it doesn't run
the code after the Else statement.
This happens around 25 times then finally the pointer moves on and
finally reaches the Exit Sub at the end.
However it does NOT exit the code as I would expect but instead
moves to the line marked C. It then moves to A. This second loop
keeps going for quite a while and I'm still stepping through it as I
write.

I really have no idea why this is happening - I can only assume it's
caused by some weird combination of events, yet I am stepping
through everything and only the lostfocus event is firing.
Any ideas?

thanks
Martin


Nov 12 '05 #4
Phil Stanton wrote:
Can't help then I was wondering if it was requerying the subform once
for each record, but no

Sorry
Thanks anyhow, i think i'm going to have to live with it until inspiration
strikes. It doesn't do any harm but i am wondering why it's happening. Or
if it only happens when I debug line by line, which would be ironic....

"Deano" <de*********@hotmail.com> wrote in message
news:EV*****************@wards.force9.net...
Phil Stanton wrote:
How many lines on your subform?


46 filtered records.


"Deano" <de*********@hotmail.com> wrote in message
news:Hn****************@wards.force9.net...
Here's the code;
Private Sub txtTeachName_LostFocus()

If IsNull(Me.txtName) Then 'line A
Forms!frmMainform!frmSubform.Locked = True
GoTo Exit_txtName
Else 'line B
Forms!frmMainform!frmSubform.Locked = False 'line C
If IsEmpty(oldName) Then
oldName = Me.Name
GoTo Exit_txtName
End If
End If

Exit_txtName:
Exit Sub

End Sub
If txtName isn't a null then I see the code jump to Else (the line
marked B) and then jump back to the first If - i.e it doesn't run
the code after the Else statement.
This happens around 25 times then finally the pointer moves on and
finally reaches the Exit Sub at the end.
However it does NOT exit the code as I would expect but instead
moves to the line marked C. It then moves to A. This second loop
keeps going for quite a while and I'm still stepping through it as
I write.

I really have no idea why this is happening - I can only assume
it's caused by some weird combination of events, yet I am stepping
through everything and only the lostfocus event is firing.
Any ideas?

thanks
Martin


Nov 12 '05 #5
de*********@hotmail.com (Deano) wrote in
<Hn****************@wards.force9.net>:
Here's the code;

Private Sub txtTeachName_LostFocus()

If IsNull(Me.txtName) Then 'line A
Forms!frmMainform!frmSubform.Locked = True
GoTo Exit_txtName
Else 'line B
Forms!frmMainform!frmSubform.Locked = False 'line C
If IsEmpty(oldName) Then
oldName = Me.Name
GoTo Exit_txtName
End If
End If

Exit_txtName:
Exit Sub

End Sub
Here's code that does the same thing:

Forms!frmMainform!frmSubform.Locked = IsNull(Me!txtName)
If (Forms!frmMainform!frmSubform.Locked) _
And IsEmpty(oldName) Then
oldName = Me.Name
End If

Now, I don't know what "oldName" refers to, but I assume it is a
form-level or public variable. I don't know why you're testing it
for "IsEmpty," which I only know about using with variants, and
even then, it's not entirely reliable.

If you're storing a string (the name of a form), then the variable
ought to be a string variable. And you'd test it with:

Len(strOldName)=0

So, your code seems vastly more complicated than it needs to be.
If txtName isn't a null then I see the code jump to Else (the line
marked B) and then jump back to the first If - i.e it doesn't run
the code after the Else statement.
Then that means that txtName is never Null. Does the field it's
bound to allow zero-length strings? If so, then it may very well be
"empty" from a human point of view and still not be Null.
This happens around 25 times then finally the pointer moves on and
finally reaches the Exit Sub at the end.
However it does NOT exit the code as I would expect but instead
moves to the line marked C. It then moves to A. This second loop
keeps going for quite a while and I'm still stepping through it as
I write.
I don't quite understand the relationships of the form. Is the form
referred to by Me the subform you're trying to lock? If so, then
you really can't do this from the subform.

I also question why you're using the LostFocus event, and not the
AfterUpdate event. I'm not certain, but there may be circumstances
where a control, loses focuses but does not fire the update events
(such as when the form the control is a part of loses focus), so
you could be testing for Null before it actually *is* Null.
I really have no idea why this is happening - I can only assume
it's caused by some weird combination of events, yet I am stepping
through everything and only the lostfocus event is firing.


I don't know what you are trying to accomplish.

Please explain what your code is doing and why, and then maybe we
can diagnose it.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #6
David W. Fenton wrote:
de*********@hotmail.com (Deano) wrote in
<Hn****************@wards.force9.net>:

<snipped>

Thanks for the tips David.

At the moment it *is* working OK but I'm so busy looking at other things I'm
not going to have time to take this further (maybe later). The issue with
the oldname variable etc is to be able to know when the name's been changed
and the control in question is on the main form. It's a validation thing
and was done many months ago. Knowing what I know now I think it could be
done alot better.

What I was hoping that this was some fundamental Access glitch or well-known
behaviour that was easy to rectify....
Nov 12 '05 #7
de*********@hotmail.com (Deano) wrote in
<OD*****************@wards.force9.net>:
David W. Fenton wrote:
de*********@hotmail.com (Deano) wrote in
<Hn****************@wards.force9.net>:

<snipped>

Thanks for the tips David.

At the moment it *is* working OK but I'm so busy looking at other
things I'm not going to have time to take this further (maybe
later). The issue with the oldname variable etc is to be able to
know when the name's been changed and the control in question is
on the main form. It's a validation thing and was done many
months ago. Knowing what I know now I think it could be done alot
better.

What I was hoping that this was some fundamental Access glitch or
well-known behaviour that was easy to rectify....


I still don't know what your problem could be because I don't knoiw
the context in which the code is running.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #8
David W. Fenton wrote:
de*********@hotmail.com (Deano) wrote in
<OD*****************@wards.force9.net>:
David W. Fenton wrote:
de*********@hotmail.com (Deano) wrote in
<Hn****************@wards.force9.net>:

<snipped>

Thanks for the tips David.

At the moment it *is* working OK but I'm so busy looking at other
things I'm not going to have time to take this further (maybe
later). The issue with the oldname variable etc is to be able to
know when the name's been changed and the control in question is
on the main form. It's a validation thing and was done many
months ago. Knowing what I know now I think it could be done alot
better.

What I was hoping that this was some fundamental Access glitch or
well-known behaviour that was easy to rectify....


I still don't know what your problem could be because I don't knoiw
the context in which the code is running.


It's OK, i'm content to drop it for the time being. At the moment I'm not
keen on revisiting code unless i have to since it means i have to work out
what it all meant in the first place. My initial post was tangential to
something else but now that is cleared up so I will leave it for the time
being.

I do however think it is an interesting problem that might be of interest to
others and will post back on this subject when time permits and I can supply
the correct level of detail.
Nov 12 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Sylvain Thenault | last post by:
Hi there ! Can someone explain me the following behaviour ? >>> l = >>> 0 in (l is False) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: iterable argument...
3
by: Philip Yale | last post by:
I'm very puzzled by the choice of NC index being made by the optimizer in this example. I don't actually think it should use an NC index at all. I have: Table: CustomerStatus_T Single data...
7
by: Jon Combe | last post by:
I have created the following test SQL code to illustrate a real problem I have with some SQL code. CREATE TABLE JCTable ( CustomerName varchar(50) ) ALTER TABLE JCTable ADD CustomerNo int...
8
by: Hostile17 | last post by:
Consider the following HTML. ---------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> <html> <head> <meta...
10
by: Chris Mantoulidis | last post by:
I see some really weird output from this program (compiled with GCC 3.3.2 under Linux). #include <iostream> using namespace std; int main() { char *s; s = "test1"; cout << "s = " << s << "...
1
by: Pankaj | last post by:
Hi All, I use a Hashtable in my program to keep unique items...at one instance I need to repopulate this hashtable through a loop. when starting repopulation hashtable.count() returns ZERO...
8
by: Daniel Yelland | last post by:
Hi, I have developed a number of code libraries in Win32 DLLs and have written a number of test suite executables that implicitly link to these libraries in order to test them. In one of my test...
38
by: baong | last post by:
dear all i have use this line to time in many my web base appl. but now i found a weird problem the javascript line is the same but i use the calculation 2 time @ the first time, it is ok, 3 *...
41
by: Petr Jakes | last post by:
Hello, I am trying to study/understand OOP principles using Python. I have found following code http://tinyurl.com/a4zkn about FSM (finite state machine) on this list, which looks quite useful for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.