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



On 30 May 2007 19:24:56 -0700, google@xxxxxxxxxxxxxxxxx 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 code> Then
[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

.