G
Gordon
I posted a question on the same subject several days b4. It was answere
by Geral Stanley. But I could not work it out with his answer. I tried som
codes. Can somebody take a look and let me know where I did wrong
[Question
When I entering a new record, I want Access to assign a new value to
the primary key automatically in the following format
AByyyy000
Where "A" stands for Agent, "B" stands for Dept, "yyyy" stands for current year, an
"0000" stands for the auto number, starting from 1
In addition, When A or B or year changes, I wan
Access to start the "0000" part from 1 again.
[My trials
I create a table with the following fields: RefNumber(text), DeptID(text), AgentID(text
and RefYear(number)
Then I make a query to count the RefNumber (NoRef) and get the max RefNumber (MaxRef)
"SELECT nz(Count([RefNumber])) AS NORef, Max(Right([RefNumber],4)) AS MaxRef,
TestRefLog.AgentID, TestRefLog.DeptID, TestRefLog.RefYear FROM TestRefLog GROUP
BY TestRefLog.AgentID, TestRefLog.DeptID, TestRefLog.RefYear;
I tried the following code on a fome try to assign a RefNumber automatically after I selec
an agent from the [SelectAgent] combo box
Private Sub SelectAgent_AfterUpdate(
Dim Counter As Lon
Dim SetYear As Lon
Dim SetAgent As Strin
Dim SetDept As Strin
SetYear = Year(Date
SetAgent = Forms![RefLogNew]![SelectAgent
SetDept = Forms![RefLogNew]![SelectDept
If DLookup("NoRef", "NoRefQuery", "AgentID=" & "'" & SetAgent & "'" AND "DeptID=" & "'" & SetDept & "'" AND "RefYear=" & SetYear) < 1 The
Counter =
Els
Counter = Nz(DLookup("MaxRef", "NoRefQuery", "AgentID=" & "'" & SetAgent & "'" AND "DeptID=" & "'" & SetDept & "'" AND "RefYear=" & SetYear)) +
End If
Me.Counter00 = SetAgent & SetDept & SetYear & Format(Counter, "0000"
End Su
[Problem
When the two DLookup has only one criteria, either AgentID only or DeptID only or RefYear only,
the code works. But with all the three criterias, I got a "run time error 13: Type mismatch"
Can somebody tell me what is wrong with me code? Thanks a lot.
by Geral Stanley. But I could not work it out with his answer. I tried som
codes. Can somebody take a look and let me know where I did wrong
[Question
When I entering a new record, I want Access to assign a new value to
the primary key automatically in the following format
AByyyy000
Where "A" stands for Agent, "B" stands for Dept, "yyyy" stands for current year, an
"0000" stands for the auto number, starting from 1
In addition, When A or B or year changes, I wan
Access to start the "0000" part from 1 again.
[My trials
I create a table with the following fields: RefNumber(text), DeptID(text), AgentID(text
and RefYear(number)
Then I make a query to count the RefNumber (NoRef) and get the max RefNumber (MaxRef)
"SELECT nz(Count([RefNumber])) AS NORef, Max(Right([RefNumber],4)) AS MaxRef,
TestRefLog.AgentID, TestRefLog.DeptID, TestRefLog.RefYear FROM TestRefLog GROUP
BY TestRefLog.AgentID, TestRefLog.DeptID, TestRefLog.RefYear;
I tried the following code on a fome try to assign a RefNumber automatically after I selec
an agent from the [SelectAgent] combo box
Private Sub SelectAgent_AfterUpdate(
Dim Counter As Lon
Dim SetYear As Lon
Dim SetAgent As Strin
Dim SetDept As Strin
SetYear = Year(Date
SetAgent = Forms![RefLogNew]![SelectAgent
SetDept = Forms![RefLogNew]![SelectDept
If DLookup("NoRef", "NoRefQuery", "AgentID=" & "'" & SetAgent & "'" AND "DeptID=" & "'" & SetDept & "'" AND "RefYear=" & SetYear) < 1 The
Counter =
Els
Counter = Nz(DLookup("MaxRef", "NoRefQuery", "AgentID=" & "'" & SetAgent & "'" AND "DeptID=" & "'" & SetDept & "'" AND "RefYear=" & SetYear)) +
End If
Me.Counter00 = SetAgent & SetDept & SetYear & Format(Counter, "0000"
End Su
[Problem
When the two DLookup has only one criteria, either AgentID only or DeptID only or RefYear only,
the code works. But with all the three criterias, I got a "run time error 13: Type mismatch"
Can somebody tell me what is wrong with me code? Thanks a lot.