storing auto values

B

B.L

I am trying to figure out a way to store or prevent
the "random" value from being re-generated each time the
command button to create the PatientCode (see below)is
clicked.
The locationcode and the abstractor code fields are
sometimes updated but when the command button is clicked
to capture these updates in the the patientcode a new 6-
digit random number is generated. Is there any code or
means of retaining the first random value generated in
the table so that it can be retrieved for the acrostic or
is there code that I can add to the patientcode module to
prevent a new number from being generated if one had been
created previously

The code used to generate the acrostic -(patientcode) is
below:

Private Sub CmdPasteRandomID_Click()
Dim RandomNumber As Long

Randomize ' Initialize random-number generator.
' Generate random value between 999, 999 And 100, 0#
Random = Int((999999 - 100000 + 1) * Rnd + 100000)
' Set random in basicshortcrf table to RandomNumber
' Set Random = RandomNumber
PatientCode = Format([AbstractorCode], "00") & Format
([LocationCode], "00") & [Random]

End Sub
Thanks in advance
 
M

Michel Walsh

Hi,


Right at the start, test if there is a value?

If Not IsNull(Me.PatientCode) Then
Exit Sub
End If


Doing so, you won't regenerate a random value if there is already a not-null
value in Me.PatientCode.



Hoping it may help
Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top