View Single Post
  #3  
Old June 26th, 2009, 09:42 AM posted to microsoft.public.access.tablesdbdesign
Keith Wilby
external usenet poster
 
Posts: 812
Default Trying to get a field to generate contents automatically on a form

"NDBC" wrote in message
...

I am trying to use access 2003 to record rider details and keep lap times
at
a local enduro race. I am trying to input riders details. There are a few
classes of competitors, a grade (rider number 100-199), b grade (rider
number
200-299) etc. I have set up an optiion group for rider class so if a grade
is
ticked it comes back with the response 100 and 200 for b grade etc. What I
need in the rider number box is the next available rider number to be
generated automatically. For instance if the a grade option is ticked and
the
largest rider number in the 100's already stored in the table is 103 then
it
automatically comes up with 104 as the rider number. All classes rider
numbers are stored in the one table at this stage. Does it make it easier
if
I have a table for each class. I don't know how to make a form look at
multiple tables.

I have developed a query that can determine the highest number used in any
class based on an input of (100, 200 etc) but don't know how to use a
query
from a form if this is an option.

I have a very limited experience with access and vba so may need very
detailed help if possible but any advice will be gladly accepted.

Thanks


I'm assuming that you're using a form to manipulate your data (as you should
be!).

I'm also assuming that you have a text box called "txtUniqueNo" bound to a
field "UniqueNo" in table "tblEnduro" and your option group is bound to a
number field "Class" and is called "ogrClass" and that the option values are
100 (a), 200 (b) etc. Something like this should work in the form's Before
Update event (untested):

Me.txtUniqueNo = Nz(DMax("UniqueNo", "tblEnduro", "[Class] = " &
Me.ogrClass)+1,Me.ogrClass)

The "Nz" handles the case where there is no number for the selected class,
in which case it will take the value assigned to the selected option.

If your Class field is a text field then you'll need to use quotation marks:

Me.txtUniqueNo = Nz(DMax("UniqueNo", "tblEnduro", "[Class] = ' " &
Me.ogrClass & " ' ")+1,Me.ogrClass)

I've included extra spaces around the single quotes for clarity, you should
not include them in your code. The number will be assigned when the record
has been saved.

Hope that makes sense.

Keith.
www.keithwilby.co.uk