Hi,
Firstly let me appologise if this has been asked before (I've tried searching and not yet found anything I can use :()
My boss has asked me to automatically generate a number for leads that get entered into our DB via a form.
The problem is that these numbers need to be prefixed with either an AG or BG (depending on which of our 2 offices the lead relates to). Selecting A or B is easy enough but what I need help with is some code to find the highest number with the selected prefix and give the new record that number + 1.
For example you may have a table with these lead numbers:
AG1
AG2
BG1
BG2
BG3
AG3
AG4
AG5
AG6
AG7
BG4
If I were to add a new record relating to the AG office I want the code to see that AG7 is the current highest number and call my new record AG8.
Once that number has been generated I want it (including the prefix) stored in a field for that record (if possible I'd like this to be the primary key as all values will be unique).
I hope that makes sense, please ask if you need any more info.
Many thanks,
Gav
Firstly let me appologise if this has been asked before (I've tried searching and not yet found anything I can use :()
My boss has asked me to automatically generate a number for leads that get entered into our DB via a form.
The problem is that these numbers need to be prefixed with either an AG or BG (depending on which of our 2 offices the lead relates to). Selecting A or B is easy enough but what I need help with is some code to find the highest number with the selected prefix and give the new record that number + 1.
For example you may have a table with these lead numbers:
AG1
AG2
BG1
BG2
BG3
AG3
AG4
AG5
AG6
AG7
BG4
If I were to add a new record relating to the AG office I want the code to see that AG7 is the current highest number and call my new record AG8.
Once that number has been generated I want it (including the prefix) stored in a field for that record (if possible I'd like this to be the primary key as all values will be unique).
I hope that makes sense, please ask if you need any more info.
Many thanks,
Gav