Access 2007 not incrementing count from Access 2003

D

David Teich

I only use it for some home databases tracking books, movies, wines, etc. The
counter that increments the main entry's key so I can link to sub-tables has
stopped working. Here's an example of the code:

----------------------------------------
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.[WineID] = Nz(DMax("[WineID]", "[Wines]"), 0) + 1

End Sub
----------------------------------------

That's worked in earlier versions of Access, upgrading ok through 03. Who
knows what's wrong that it no longer works in Access 2007?

thanx.
 
D

David Teich

No, initially they were, but I enabled them. The other macros and event
coding seem to be working fine. It's just that, as far as I can see.

David
 
S

Stuart McCall

David Teich said:
I only use it for some home databases tracking books, movies, wines, etc.
The
counter that increments the main entry's key so I can link to sub-tables
has
stopped working. Here's an example of the code:

----------------------------------------
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.[WineID] = Nz(DMax("[WineID]", "[Wines]"), 0) + 1

End Sub
----------------------------------------

That's worked in earlier versions of Access, upgrading ok through 03. Who
knows what's wrong that it no longer works in Access 2007?

thanx.

One thing you could try is to break apart the line, making it better
debuggable:

Dim tmp As Variant
tmp = DMax("[WineID]", "[Wines]")
If Isnull(tmp) Then tmp = 0
Me.[WineID] = tmp + 1

Single-step through that and see if that turns up something (I don't have
A2007 so can't try it for you)
 
D

David Teich

Now the weird part. I used your code, put a break point in the first line,
then added a record. It didn't break. Any reason why Before Insert would no
longer be fired in 07?

I'll now check Ling's links too.

David

Stuart McCall said:
David Teich said:
I only use it for some home databases tracking books, movies, wines, etc.
The
counter that increments the main entry's key so I can link to sub-tables
has
stopped working. Here's an example of the code:

----------------------------------------
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.[WineID] = Nz(DMax("[WineID]", "[Wines]"), 0) + 1

End Sub
----------------------------------------

That's worked in earlier versions of Access, upgrading ok through 03. Who
knows what's wrong that it no longer works in Access 2007?

thanx.

One thing you could try is to break apart the line, making it better
debuggable:

Dim tmp As Variant
tmp = DMax("[WineID]", "[Wines]")
If Isnull(tmp) Then tmp = 0
Me.[WineID] = tmp + 1

Single-step through that and see if that turns up something (I don't have
A2007 so can't try it for you)
 
D

David Teich

Busy week, but read the link on Ling's and the walk through didn't show
anything obvious. I tried testing the code again, and the watch list showed
the tmp variable being incremented but just not input into the field in the
record.

On a whim, I copied the code into "before update" and modified a record. It
worked. So now I'm really confused. It seems to be a problem of Before
Instert not wanting to do what it's being told to do. Does anyone have a clue
why that stopped working between versions? What about Before Insert changed
that the exact same code works Before Update but not there?

thanx,
David

David Teich said:
Now the weird part. I used your code, put a break point in the first line,
then added a record. It didn't break. Any reason why Before Insert would no
longer be fired in 07?

I'll now check Ling's links too.

David

Stuart McCall said:
David Teich said:
I only use it for some home databases tracking books, movies, wines, etc.
The
counter that increments the main entry's key so I can link to sub-tables
has
stopped working. Here's an example of the code:

----------------------------------------
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.[WineID] = Nz(DMax("[WineID]", "[Wines]"), 0) + 1

End Sub
----------------------------------------

That's worked in earlier versions of Access, upgrading ok through 03. Who
knows what's wrong that it no longer works in Access 2007?

thanx.

One thing you could try is to break apart the line, making it better
debuggable:

Dim tmp As Variant
tmp = DMax("[WineID]", "[Wines]")
If Isnull(tmp) Then tmp = 0
Me.[WineID] = tmp + 1

Single-step through that and see if that turns up something (I don't have
A2007 so can't try it for you)
 

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