S
Slez via AccessMonster.com
I have some code written in the BeforeUpdate event so that when users enter a
new record into a subform, it sort of auto-numbers those records. It works
perfectly and is as follows:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.SampleID) Then
Me!SampleID = Nz(DMax("SampleID", "tblFinishSample", "[JobNumber]='"
& [JobNumber] & "'"), 0) + 1
End If
End Sub
I am now working in another database with a very similar application, so I
pasted the above code into this other database and switched the table and
field references, thinking it should be a perfect fit. The revised version
is as follows.
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.BidNumber) Then
Me!BidNumber = Nz(DMax("BidNumber", "Bid", "[ProjectID]='" &
[ProjectID] & "'"), 0) + 1
End If
End Sub
However, I get a "Run-time error '3464': Data type mismatch in criteria
expression". The only difference with this other database is that there is
one additional linked field. Besides ProjectID, there is also ProjectName,
which is an additional primary key in the tables. It seems to me that this
would need to be included in the expression, but I am uncertain how to
include it. If anyone can offer assistance, I would greatly appreciate it.
This leads me to also requesting some additional advice. When I was
initially creating this database a year ago, I had someone help me work
through some glitches. They added the field ProjectID to my tables, which
already had a unique field called ProjectName. At the time, it worked great,
but now that I am creating more forms and subforms, I am having that
additional master/child link which does make some expressions more
complicated. I'm considering eliminating the ProjectName field from all
tables except the "Project" table (which is the "one" side of all other
relationships). Being part of the primary keys for each table requires
deletion of relationships and recreating them. With all that said, does this
seem like the right thing to do in the long-term?...Or is that viewed as a
trivial thing and I should just leave things alone. I feel having an extra
primary key is unnecessary, but am curious if others have an opinion.
Eliminating this would also result in the previously mentioned code working
as is...I think!
Thanks
Slez
new record into a subform, it sort of auto-numbers those records. It works
perfectly and is as follows:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.SampleID) Then
Me!SampleID = Nz(DMax("SampleID", "tblFinishSample", "[JobNumber]='"
& [JobNumber] & "'"), 0) + 1
End If
End Sub
I am now working in another database with a very similar application, so I
pasted the above code into this other database and switched the table and
field references, thinking it should be a perfect fit. The revised version
is as follows.
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.BidNumber) Then
Me!BidNumber = Nz(DMax("BidNumber", "Bid", "[ProjectID]='" &
[ProjectID] & "'"), 0) + 1
End If
End Sub
However, I get a "Run-time error '3464': Data type mismatch in criteria
expression". The only difference with this other database is that there is
one additional linked field. Besides ProjectID, there is also ProjectName,
which is an additional primary key in the tables. It seems to me that this
would need to be included in the expression, but I am uncertain how to
include it. If anyone can offer assistance, I would greatly appreciate it.
This leads me to also requesting some additional advice. When I was
initially creating this database a year ago, I had someone help me work
through some glitches. They added the field ProjectID to my tables, which
already had a unique field called ProjectName. At the time, it worked great,
but now that I am creating more forms and subforms, I am having that
additional master/child link which does make some expressions more
complicated. I'm considering eliminating the ProjectName field from all
tables except the "Project" table (which is the "one" side of all other
relationships). Being part of the primary keys for each table requires
deletion of relationships and recreating them. With all that said, does this
seem like the right thing to do in the long-term?...Or is that viewed as a
trivial thing and I should just leave things alone. I feel having an extra
primary key is unnecessary, but am curious if others have an opinion.
Eliminating this would also result in the previously mentioned code working
as is...I think!
Thanks
Slez