The field is a 17 digit text field example "W915BQ43220851XXX" . If you have
ever been in the military regardless of branch, you will recognize this as a
TCN # or TMR #. If not, no big deal, this is a transportation code for cargo,
air cargo in this case. I work for the Army, preparing and transporting air
cargo on the Air Force cargo jets. What I have developed is a Access program
to accomplish the paperwork in a more efficient manner. Using the "Duplicate"
button helps speeds this process. The problem I have is this TMR/TCN cannot
be a duplicate once used it is never good again. Ideally I would have a
button to duplicate al of the cargo information except the TCN/TMR or have it
automatically change the TCN/TMR even if it is the last digit being the "X"
changing to a numeric value that increased per duplicate. Current I have the
table properties for this field set to duplicates ok, but I really shouldn't
have it set that way. Unfortunately being self Access taught I do not posses
the knowledge, YET, to write a VBA to expound on the current capabilities of
Access. If you can provide guidance I would greatly appreciate it.
Steve
Well, it will require some VBA code to determine the last "x" and take
appropriate action. If the last digit is 3 then you could increase it
to 4 - but what if it's 9? or worse, if the last three digits are 999?
What if you increment the value and still get a duplicate: how should
the program respond?
Here's some suggested code that will *partially* resolve the issue. It
will find the largest existing TCN/TMR value in the table (which might
not be the most recently entered one!), increment the last three
digits, and pop a message box warning of a duplicate if that's not
possible or if doing so generates another duplicate. Open your Form in
design view, view its Properties, select the BeforeInsert event on the
Events tab, and invoke the Code Builder. Adjust fieldnames as needed
to match your database.
Private Sub Form_BeforeInsert(Cancel as Integer)
Dim strTCN As String
Dim iSeq As Integer
strTCN = DMax("[TCN_TMR]", "[YourTable]")
iSeq = Right([strTCN], 3) ' extract last three bytes, convert to num
If iSeq < 999 Then
' build a new TCN by incrementing value and concatenating string
strTCN = Left(strTCN, 14) & Format(iSeq + 1, "000")
Else
MsgBox "Ran out of numbers, hand-assign TCN/TMR", vbOKOnly
Exit Sub
End If
If IsNull(DLookUp("[TCN/TMR]", "yourtable", "[TCN/TMR] = '" _
& strTCN & "'") Then ' If the new value doesn't exist, add it
Me!txtTCN_TMR = strTCN ' use your own textbox name of course
Else
MsgBox "Autogenerated TCN/TMR causes a duplicate, enter manually", _
vbOKOnly
End If
End Sub
Air code, untested - post back if it doesn't work.
And... good luck and God bless you and all the troops you're
supporting.
John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps