Generate ID number if certain criteria met

statadm

New member
Local time
Today, 12:40
Joined
Mar 25, 2010
Messages
4
I was going to use autonumber to generate a unique ID number (not primary key), but now I need to generate this number only if some criteria are met.

Does anyone have some coding suggestions for doing this?

All criteria being use to determine if they should be assigned an ID number are checkboxes.

Thanks in advance!
 
A record should contain an ID number. What is your objective?

Welcome to AWF by the way :)
 
You may wish to consider an alternate method of assigning your number as the AutoNumber will assign a new number as soon as the first character is typed into any field on your form.

Consider Dmax() +1 to assign your own sequential numbers
 
Or store your "autonumber" in a different table with a FK from the table that references it.
 
It sounds like I didn't make myself clear.

I use an autonumber for my PK, but I do need to create another kind of auto generated ID number that will be assigned only to those that meet some certain criteria true/false.

Dmax +1 is exactly what I want, but I want to also define some kind of where criteria. Specifically, the where criteria is related to checkboxes. I want to either define 5 specific checkboxes all as false or 6 other checkboxes all as true.

I just can't seem to find how to get this to work with Dmax().

Thanks!
 
Last edited:
Also, where is the base place to put this Dmax() function so that the generated ID appears in the form once the checkbox "criteria" are selected. This generated ID will then be used in another web based application to enter deidentified information (aside from ID).
The access database is used for tracking purposes only.
 
How many check boxes are you checking against in order to determine whether the unique number should be created?

What is the format of this unique number/string?
 
So the way it is set up is that 4 boxes have to be checked and none of 6 additional boxes can be checked in order to get this unique ID number. If one of the 6 additional boxes are checked than they should NOT get an ID number. If one of the 4 boxes are NOT checked then they will not get an ID number. The ID number will just start with 1 and should eventually go to 8000.

I'm open to changing the checkboxes for a better format. I just have to know that some 4 criteria are met and some 6 criteria are not met in order to generate an ID.
 
1. Give each of the 6 checkboxes a TAG property of "6_Checked"
2. Give each of the 4 checkboxes a TAG property of "4_Checked"

Without the quotes.

You would check against the tag in the controls collection and count how many of these where checked. This should get you started (air code):
Code:
Dim ctl As control, getID as boolean

getid = true

    For Each ctl In Me
        If TypeName(ctl) = "CheckBox" Then
            If ctl.Tag = "6_Checked" and ctl.value = True Then
                 getId = false
                 exit for
            end if
        end if
    next

    if getid = true then
        For Each ctl In Me
            If TypeName(ctl) = "CheckBox" Then
                If ctl.Tag = "4_Checked" and ctl.value = false Then
                     getId = false
                     exit for
                end if
            end if
        next
 
        if getid = true then
             .... assign id
        end if
    else
         ... assign id
    end if
 

Users who are viewing this thread

Back
Top Bottom