field inserted after rest of field, needs to be at same time

G

Guest

I have a piece of my code below in which a random number is created (RandomNum)
In the code below the random number is being inserted in a new row after all
of the other information. So I have 2 rows being inserted one with all of
the patient information and no random number it the field it is suppose to be
in then second row has no patient information but has the random number.

How can I get the random number to be inserted at the same time as the rest
of the information.

Randomize
RandomNum = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

If DCount("[geneticIDnumber]", "[Patient_Registry]", "[geneticIDnumber]=" &
RandomNum) = 0 Then

If LongTermConsent.Value <> Yes Or No Then
strSQL = "INSERT INTO Patient_Registry (geneticIDnumber) " & "VALUES
(" & RandomNum & ");"
CurrentDb.Execute strSQL
DoCmd.GoToRecord , , acNewRec
Else
MsgBox ("All Fields must be entered")
End If
End If
 
M

Marshall Barton

pokdbz said:
I have a piece of my code below in which a random number is created (RandomNum)
In the code below the random number is being inserted in a new row after all
of the other information. So I have 2 rows being inserted one with all of
the patient information and no random number it the field it is suppose to be
in then second row has no patient information but has the random number.

How can I get the random number to be inserted at the same time as the rest
of the information.

Randomize
RandomNum = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

If DCount("[geneticIDnumber]", "[Patient_Registry]", "[geneticIDnumber]=" &
RandomNum) = 0 Then

If LongTermConsent.Value <> Yes Or No Then
strSQL = "INSERT INTO Patient_Registry (geneticIDnumber) " & "VALUES
(" & RandomNum & ");"
CurrentDb.Execute strSQL
DoCmd.GoToRecord , , acNewRec
Else
MsgBox ("All Fields must be entered")
End If
End If


INSERT INTO is supposed to append a new record.

How is the rest of the data being saved tp the table? If
it's the current record on the form, then instead of
appending a record, just set the random number to the
related text box:

Me.txtgeneticIDnumber = RandomNum
 

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