473,407 Members | 2,676 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,407 software developers and data experts.

Access 2007 bug? Focus does not stay on new record in code

In a continuous form the following code is under a button in the form
header. In Access 2003 and earlier, this goes to a new record, then
adds
relevant data to that new record.

DoCmd.GoToRecord , , A_NEWREC

If <some codeThen
[AItemNumber] = "CA002"
Else
'Some other code
End If

Call InsertItemDetails 'This procedure adds other data to
the new
record by looking up data that matches [AItemNumber]=CA002

The InsertItemDetails procedure contains lots of code including
statements such as

If [AItemNumber] = "CA002" Then
'Insert some data into the record
End If
In Access 2007, this process creates the new record, and adds the
CA002
value to the field [AItemNumber]. However the focus in code does not
go
to the new record, but rather stays on the existing record. If the
current record (before clicking the NEw Item button) has e.g. CB100 in
the [AItemNumber] field, incorrect data is put into the new record.
When
stepping through the code, although a new record has been created on
the
form with [AItemNumber]=CA002, hovering over the [AItemNumber] text in
the code shows the value to be CB100. In other words, the form has
gone
to a new record but the code hasn't. Later when I use the If
[AitemNumber] = statement, the value CB100 is used instead of CA002.
In
Access 2003, the same code uses the CA002 value.

Has anyone experienced this? Is it a 2007 bug? Can you suggest any
workarounds? Maybe I need to save the new record and specifically
navigate to it before adding any extra data from code?

Thanks
Owen Jenkins

May 31 '07 #1
16 3521
On 30 May 2007 19:24:56 -0700, go****@healthbase.com.au wrote:

I just tried these 2 lines:
RunCommand acCmdRecordsGoToNew
Me.SomeTextField = "HELLO WINDOWS"
in a continuous form, and it worked as expected: the cursor went to a
new record, the field now has the value, and focus is on that row, on
the (first) ID field.

You may want to use an elimination strategy to see where your code
goes south.

-Tom.
>In a continuous form the following code is under a button in the form
header. In Access 2003 and earlier, this goes to a new record, then
adds
relevant data to that new record.

DoCmd.GoToRecord , , A_NEWREC

If <some codeThen
[AItemNumber] = "CA002"
Else
'Some other code
End If

Call InsertItemDetails 'This procedure adds other data to
the new
record by looking up data that matches [AItemNumber]=CA002

The InsertItemDetails procedure contains lots of code including
statements such as

If [AItemNumber] = "CA002" Then
'Insert some data into the record
End If
In Access 2007, this process creates the new record, and adds the
CA002
value to the field [AItemNumber]. However the focus in code does not
go
to the new record, but rather stays on the existing record. If the
current record (before clicking the NEw Item button) has e.g. CB100 in
the [AItemNumber] field, incorrect data is put into the new record.
When
stepping through the code, although a new record has been created on
the
form with [AItemNumber]=CA002, hovering over the [AItemNumber] text in
the code shows the value to be CB100. In other words, the form has
gone
to a new record but the code hasn't. Later when I use the If
[AitemNumber] = statement, the value CB100 is used instead of CA002.
In
Access 2003, the same code uses the CA002 value.

Has anyone experienced this? Is it a 2007 bug? Can you suggest any
workarounds? Maybe I need to save the new record and specifically
navigate to it before adding any extra data from code?

Thanks
Owen Jenkins
May 31 '07 #2
I just tried these 2 lines:
RunCommand acCmdRecordsGoToNew
Me.SomeTextField = "HELLO WINDOWS"
in a continuous form, and it worked as expected: the cursor went to a
new record, the field now has the value, and focus is on that row, on
the (first) ID field.

You may want to use an elimination strategy to see where your code
goes south.
Well for me, the cursor goes to the new record and inserts the
specified text, but if the code then says If Me.SomeTextField="HELLO
WINDOWS" Then, this evaluates as false.

Owen

May 31 '07 #3
On 30 May 2007 21:59:42 -0700, Owen <go****@healthbase.com.auwrote:

Ah, I think you're onto something. I can confirm this behavior to be
different between A2000 and A2007.
My code:
RunCommand acCmdRecordsGoToNew
Me.CategoryName = "Hello"
Me.CategoryName.SetFocus
Debug.Print Me.CategoryName = "Hello", Me.CategoryName.Value,
Me.CategoryName.Text

In A2000 it prints the data about the new record, whereas in A2007 it
prints the data about the record you came from. Even when I added the
SetFocus line.

Weird. Will have to look at that some more.

-Tom.
>I just tried these 2 lines:
RunCommand acCmdRecordsGoToNew
Me.SomeTextField = "HELLO WINDOWS"
in a continuous form, and it worked as expected: the cursor went to a
new record, the field now has the value, and focus is on that row, on
the (first) ID field.

You may want to use an elimination strategy to see where your code
goes south.

Well for me, the cursor goes to the new record and inserts the
specified text, but if the code then says If Me.SomeTextField="HELLO
WINDOWS" Then, this evaluates as false.

Owen

May 31 '07 #4
Ahhh, thank you! It's not just me then. This could affect a lot of
applications I expect. The failure of the SetFocus instruction is a
little alarming. It looks like I need to save the record then go to
the specific record. That could be a lot of fiddling for my fairly
code intensive app. Any suggestions for the moment? It's a bit
reminicient of the famous bookmark bug.

Owen

Jun 1 '07 #5
On Thu, 31 May 2007 20:45:29 -0700, Owen <go****@healthbase.com.au>
wrote:

I did a bit more research and the bug persists. It occurs in ADP as
well as in ACCDB. It occurs with 3 different ways of going to a new
record (see code below). I don't have a good workaround yet. I would
report this one to Microsoft.
http://support.microsoft.com/gp/contactbug
RunCommand acCmdRecordsGoToNew
Me.CategoryName = "Hello"
Me.CategoryName.SetFocus
Debug.Print Me.CategoryID, Me.CategoryName = "Hello",
Me.CategoryName.Value, Me.CategoryName.Text

With Me.RecordsetClone
.AddNew
Me.Bookmark = .Bookmark
Me.CategoryName = "Hello"
Me.CategoryName.SetFocus
Debug.Print Me.CategoryID, Me.CategoryName = "Hello",
Me.CategoryName.Value, Me.CategoryName.Text
End With

DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
Me.CategoryName = "Hello"
Me.CategoryName.SetFocus
Debug.Print Me.CategoryID, Me.CategoryName = "Hello",
Me.CategoryName.Value, Me.CategoryName.Text

-Tom.

>Ahhh, thank you! It's not just me then. This could affect a lot of
applications I expect. The failure of the SetFocus instruction is a
little alarming. It looks like I need to save the record then go to
the specific record. That could be a lot of fiddling for my fairly
code intensive app. Any suggestions for the moment? It's a bit
reminicient of the famous bookmark bug.

Owen
Jun 2 '07 #6
On Sat, 02 Jun 2007 12:44:33 -0700, Tom van Stiphout
<no*************@cox.netwrote:

Also, this bug does not depend on which form view is selected: it
happens with Single Form and Datasheet as well.

-Tom.

<clip>
Jun 2 '07 #7
Tom, I can't reproduce this problem.

Using A2007 on Vista, your first block gives the expected results:
RunCommand acCmdRecordsGoToNew
Me.CategoryName = "Hello"
Me.CategoryName.SetFocus
Debug.Print Me.CategoryID, Me.CategoryName = "Hello", _
Me.CategoryName.Value, Me.CategoryName.Text
That is:
a) the form moves to the new record.
b) the correct field displays the value Hello.
c) the correct field gets focus.
d) the debug window displays the new ID, True, Hello, Hello.
Your second block will not work reliably. The AddNew causes the clone set to
open its own buffer. The bookmark ought to fail, since the new record in the
clone set is only a buffer; it is not yet a saved record and should not have
any bookmark. However *all* versions of Access (at least as far back as
Access 2) return spurious information when you refer to the bookmark of the
new record where an edit has already begun. And, it is generally the last
record that was current before moving to the new record. So, the line:
Me.Bookmark = .Bookmark
is invalid and should fail, but actually gives wrong results in all versions
of Access.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Tom van Stiphout" <no*************@cox.netwrote in message
news:bq********************************@4ax.com...
On Thu, 31 May 2007 20:45:29 -0700, Owen <go****@healthbase.com.au>
wrote:

I did a bit more research and the bug persists. It occurs in ADP as
well as in ACCDB. It occurs with 3 different ways of going to a new
record (see code below). I don't have a good workaround yet. I would
report this one to Microsoft.
http://support.microsoft.com/gp/contactbug
RunCommand acCmdRecordsGoToNew
Me.CategoryName = "Hello"
Me.CategoryName.SetFocus
Debug.Print Me.CategoryID, Me.CategoryName = "Hello",
Me.CategoryName.Value, Me.CategoryName.Text

With Me.RecordsetClone
.AddNew
Me.Bookmark = .Bookmark
Me.CategoryName = "Hello"
Me.CategoryName.SetFocus
Debug.Print Me.CategoryID, Me.CategoryName = "Hello",
Me.CategoryName.Value, Me.CategoryName.Text
End With

DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
Me.CategoryName = "Hello"
Me.CategoryName.SetFocus
Debug.Print Me.CategoryID, Me.CategoryName = "Hello",
Me.CategoryName.Value, Me.CategoryName.Text

-Tom.

>>Ahhh, thank you! It's not just me then. This could affect a lot of
applications I expect. The failure of the SetFocus instruction is a
little alarming. It looks like I need to save the record then go to
the specific record. That could be a lot of fiddling for my fairly
code intensive app. Any suggestions for the moment? It's a bit
reminicient of the famous bookmark bug.

Owen
Jun 3 '07 #8
On Sun, 3 Jun 2007 23:54:55 +0800, "Allen Browne"
<Al*********@SeeSig.Invalidwrote:

Strange. First block prints the old record for me (and I'm guessing
for the OP as well). Tried it with both an ADP as well as an ACCDB.
I'm on WinXP, fully patched. My machine also has several other
versions of Access on it. Will try it on a few machines at work
tomorrow.

I agree I should have left out code block #2.

-Tom.

>Tom, I can't reproduce this problem.

Using A2007 on Vista, your first block gives the expected results:
RunCommand acCmdRecordsGoToNew
Me.CategoryName = "Hello"
Me.CategoryName.SetFocus
Debug.Print Me.CategoryID, Me.CategoryName = "Hello", _
Me.CategoryName.Value, Me.CategoryName.Text
That is:
a) the form moves to the new record.
b) the correct field displays the value Hello.
c) the correct field gets focus.
d) the debug window displays the new ID, True, Hello, Hello.
Your second block will not work reliably. The AddNew causes the clone set to
open its own buffer. The bookmark ought to fail, since the new record in the
clone set is only a buffer; it is not yet a saved record and should not have
any bookmark. However *all* versions of Access (at least as far back as
Access 2) return spurious information when you refer to the bookmark of the
new record where an edit has already begun. And, it is generally the last
record that was current before moving to the new record. So, the line:
Me.Bookmark = .Bookmark
is invalid and should fail, but actually gives wrong results in all versions
of Access.
Jun 3 '07 #9
I appreciate your following up this issue.
The problem is certainly reproducible. For me, block 1 always returns
data from the previously current record not the new record. This
happens in A2007 (mdb) on Vista, but not in A2003 on vista, or A2000
or A2003 on XPPro. I haven't tried A2007 on XP.

Owen

Jun 4 '07 #10
Owen, after some communication with Tom van Stiphout, I can confirm the
problem in A2007 also.

The problem seems to be that if you change record in the Click event, the
code continues to report the old record until the Click event terminates.

This is true regardless of how the record is changed, including RunCommand
acCmdGoto..., DoCmd.GotoRecord, FindFirst on the form's RecordsetClone, etc,
and even a Requery.

It is not a timing issue: you can even add a STOP to the event procedure.
Even after resuming from a long pause, it still reports the old record and
not the current one.

The problem occurs in the Click event of an image control, label, text box,
etc, but in my tests the problem did not show up in the Click event of a
command button.

It does occur in an MDB as well as an ACCDB. Earlier versions of Access did
not have this wrong behavior.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Owen" <go****@healthbase.com.auwrote in message
news:11*********************@q19g2000prn.googlegro ups.com...
>I appreciate your following up this issue.
The problem is certainly reproducible. For me, block 1 always returns
data from the previously current record not the new record. This
happens in A2007 (mdb) on Vista, but not in A2003 on vista, or A2000
or A2003 on XPPro. I haven't tried A2007 on XP.

Owen
Jun 4 '07 #11
Allen,

Thanks, you've obviously spent some time on this. So what to do next?
I sent a message to Microsoft using their generic contact form and
providing a link to this discussion but have no idea if this will get
to the relevant people. Any idea whether we could expect this to be
fixed sometime soon, or even at all?

Owen

Jun 5 '07 #12
Okay, Owen, I have logged the bug with Microsoft, so they are aware of it.
They have a little sample db I created to demonstrate the bug.

MS will then decide whether this bug will affect enough people to be worth
fixing or not. Since the previous versions worked correctly, they might, but
don't hold your breath. Unless some very large customers (or a very large
number of customers) complain, I doubt you will see a special hotfix.

In the mean time, I was not able to produce the problem with a command
button, so you may be able to use that as a workaround. Not as pretty as the
image control, but it at least it gives you a workaround.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Owen" <go****@healthbase.com.auwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...
Allen,

Thanks, you've obviously spent some time on this. So what to do next?
I sent a message to Microsoft using their generic contact form and
providing a link to this discussion but have no idea if this will get
to the relevant people. Any idea whether we could expect this to be
fixed sometime soon, or even at all?

Owen
Jun 5 '07 #13
Thanks Allen.
I'll try the command button. I'm currently using a combobox, but will
have to check my code for other instances of the problem.
Is there an easy way to find out when/if a fix becomes available?
Owen

Jun 5 '07 #14
Hmm. If a hotfix is released, there will be a KB article. If it's fixed as
part of a service pack, the issues may be listed in a KB as well.

If you want to stay up with them all, Jeff Conrad (alias the Access Junkie)
maintains a list here:
http://accessjunkie.com/kb.aspx
or you can search for yourself at:
http://support.microsoft.com/search/?adv=1

I have added your bug to the list at:
http://allenbrowne.com/Access2007.html#Bugs
Ultimately, I plan to update that if Microsoft fixes it.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Owen" <go****@healthbase.com.auwrote in message
news:11**********************@p47g2000hsd.googlegr oups.com...
Thanks Allen.
I'll try the command button. I'm currently using a combobox, but will
have to check my code for other instances of the problem.
Is there an easy way to find out when/if a fix becomes available?
Owen
Jun 5 '07 #15
Thanks!

Jun 5 '07 #16
On Mon, 04 Jun 2007 19:35:02 -0700, Owen <go****@healthbase.com.au>
wrote:

The workaround I would propose is not to rely on the new record at
all. Remember where this started: you programmatically enter data in a
new row, and while that's happening want to read back some of what has
been entered.
Certainly the code could be restructured so that isn't necessary. For
example you could create a UDT corresponding to the table, do all your
magic filling it, and once you're completely done, write it in its
entirety to a new record. If in the meantime you wanted to know the
value of one of the field, read it from the UDT.

-Tom.

>Thanks Allen.
I'll try the command button. I'm currently using a combobox, but will
have to check my code for other instances of the problem.
Is there an easy way to find out when/if a fix becomes available?
Owen
Jun 5 '07 #17

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

Similar topics

49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
3
by: David Altemir | last post by:
I have a button on "Form A" in the right margin of every record in my recordset. When you click on a button, a dialog box ("Form B") pops up that gives more details about that particular record. ...
37
by: jasmith | last post by:
How will Access fair in a year? Two years? .... The new version of Access seems to service non programmers as a wizard interface to quickly create databases via a fancy wizard. Furthermore, why...
37
by: Allen Browne | last post by:
If you develop for others, you probably have multiple versions of Access installed so you can edit and create MDEs for clients in different versions. This works fine under Windows XP, even with...
0
by: ARC | last post by:
Hello, I like the split forms in access 2007, because you can still do the header, and any tool buttons, yet have the datasheet look without the need for 2 forms (main form / subform). However,...
3
by: cwoll | last post by:
Hi I need help. I have a ms access 2003 database that I would like to upgrade to ms access 2007. The first time I opened I had to fix a few references it wanted a DAO2535.TLB file witch I gave it,...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
12
by: pballou | last post by:
The is a simple example of code that worked in access 2003 but does not in access 2007. I have checked it with the debugger and the reason is the value of formField1 does not change in ver. 2007...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.