M
MKammerer via AccessMonster.com
I have been trying everything I can to get this to work and I'm still stumped.
I have a table which has numeric primary keey value which is set by a default
value expression but the last 2 digits of the default value expression are
always 01 and I would like to be able to increase that value to 02, 03, 04 ...
etc. as more records are entered. Using an autonumber field would not work
because the default value expression uses today's date to calculate an ID
number and then adds the 2 digits so that more than 1 record can be created
in a single day. Anyhow I have been using a form to add records to the field
and been using the BeforeUpdate event on the text field of the Primary Key to
test the table and see if the Default Expression is already present in the
table. If so then it simply adds 1 to the field. I went through a long task
of finally getting the syntax right on the DCount expression I use and now I
get no errors but the process of adding 1 doesn't seem to be happening
properly. Ieven added a new text box and told the function to update that
text box instead of the one containing the primary key just to test that the
function was working, and no dice, that new text box stays empty when I enter
a known duplicate value. The BeforeUpdate function I'm using is below:
Private Sub Article_ID_BeforeUpdate(Cancel As Integer)
Dim AID As Long
Dim stLinkCriteria As String
AID = Me.Article_ID
stLinkCriteria = "[Article ID] = " & AID
If DCount("[Article ID]", "Articles", stLinkCriteria) > 1 Then
Me.Text16 = AID + 1
End If
End Sub
Articles is the table containing the numeric primary key
[Article ID] is the name of the numeric primary key in Articles
Me.Article_ID is the text box on the form whose control source is [Article ID]
me.Text16 is a temporary text box I created to test the function
Not sure where to go from here. Any help would be appreciated. Thanks.
I have a table which has numeric primary keey value which is set by a default
value expression but the last 2 digits of the default value expression are
always 01 and I would like to be able to increase that value to 02, 03, 04 ...
etc. as more records are entered. Using an autonumber field would not work
because the default value expression uses today's date to calculate an ID
number and then adds the 2 digits so that more than 1 record can be created
in a single day. Anyhow I have been using a form to add records to the field
and been using the BeforeUpdate event on the text field of the Primary Key to
test the table and see if the Default Expression is already present in the
table. If so then it simply adds 1 to the field. I went through a long task
of finally getting the syntax right on the DCount expression I use and now I
get no errors but the process of adding 1 doesn't seem to be happening
properly. Ieven added a new text box and told the function to update that
text box instead of the one containing the primary key just to test that the
function was working, and no dice, that new text box stays empty when I enter
a known duplicate value. The BeforeUpdate function I'm using is below:
Private Sub Article_ID_BeforeUpdate(Cancel As Integer)
Dim AID As Long
Dim stLinkCriteria As String
AID = Me.Article_ID
stLinkCriteria = "[Article ID] = " & AID
If DCount("[Article ID]", "Articles", stLinkCriteria) > 1 Then
Me.Text16 = AID + 1
End If
End Sub
Articles is the table containing the numeric primary key
[Article ID] is the name of the numeric primary key in Articles
Me.Article_ID is the text box on the form whose control source is [Article ID]
me.Text16 is a temporary text box I created to test the function
Not sure where to go from here. Any help would be appreciated. Thanks.