G
Guest
Commit = DLookup(Nz(DMax("commit", "commit", "[commit] = " _
& Forms!Form![Commit], 0) + 1))
What is wrong with this?
& Forms!Form![Commit], 0) + 1))
What is wrong with this?
Klatuu said:Almost everything.
You don't need the DLookup.
This should get what it appears you want:
Commit = Nz(DMax("commit", "commit", "[commit] = " & _
Forms!Form![Commit], 0) + 1)
How about some reasonable naming.
A table named commit
A field in the commit table named commit
A control on a form named commit
and I would hazard a guess the form is named commit
It is good that the names used relate to the same data element; however,
to
avoid any ambiguity for Access or the poor schmuck that has to debug your
code, add some prefixes:
Table = tblCommit
Field = commit
Control = txtCommit
And probably
Form = frmCommit
Now, everyone knows what object you are addressing easily.
ca1358 said:Commit = DLookup(Nz(DMax("commit", "commit", "[commit] = " _
& Forms!Form![Commit], 0) + 1))
What is wrong with this?
John Spencer said:I think that the proposed change has misplaced parentheses. Shouldn't that
read
Commit = NZ(DMax("Commit","Commit","Commit=" & Forms!Form![Commit] ),0) +1
Note to poster: "What's wrong with this?" is not a good question. A better
question is "why do I get the following error?" or "Why do I get this value
??? when I am expecting this value ???" Also, an explanation of what you
are trying to accomplish (in addition to the how you posted) is often
helpful in coming up with a valid solution.
As Klatuu suggested you probably don't need the DLookup at all.
Your naming practice makes things hard to understand.
Also, if your table Commit doesn't have a zero value in it and then the
DLookup will return null if the DMax function returns null. I expect the
actual nesting should be
NZ(DLookup(NZ(DMax(),0)),0)
All in all a pretty messy expression. Which
Klatuu said:Almost everything.
You don't need the DLookup.
This should get what it appears you want:
Commit = Nz(DMax("commit", "commit", "[commit] = " & _
Forms!Form![Commit], 0) + 1)
How about some reasonable naming.
A table named commit
A field in the commit table named commit
A control on a form named commit
and I would hazard a guess the form is named commit
It is good that the names used relate to the same data element; however,
to
avoid any ambiguity for Access or the poor schmuck that has to debug your
code, add some prefixes:
Table = tblCommit
Field = commit
Control = txtCommit
And probably
Form = frmCommit
Now, everyone knows what object you are addressing easily.
ca1358 said:Commit = DLookup(Nz(DMax("commit", "commit", "[commit] = " _
& Forms!Form![Commit], 0) + 1))
What is wrong with this?