Hi all,
I am setting up a database which includes a table of clients (tblClient) and a table of projects (tblProjects).
tblClients has a field called ClientID which is an integer.
tblProjects has a field called Client that looks up the ClientID from tblClients, linking the project to a client. There is also a field called ProjectID which is also an integer.
In a form designed to input new project info, I am looking for a way to autofill the project number with the next integer in the series once the Client has been chosen from the lookup combo box (called lstClient).
I have attempted some VBA to do this but it just gives 1 as the project number every time.
Code:
Private Sub ProjectID_AfterUpdate()
Dim HighestClientProject As Integer
HighestClientProject = DMax("ProjectID", "tblProject", "Client=" & lstClient)
Me = HighestClientProject + 1
End Sub
Effectively this is the kind of client & project number progression I would like to achieve:
Client / Project
1/1
1/2
2/1
2/2
2/3
2/4
3/1
3/2
I hope that makes sense. I am a VBA noob. Can anyone give me a pointer in the right direction?