Update field in another field

DeepTrouble

Registered User.
Local time
Today, 16:42
Joined
Apr 24, 2001
Messages
18
Thanks in Advance for the solution!
The database in question is for a medical laboratory. While main form is entered, a specimen number is generated automatically. However, each section of the lab wants their own serial number.I have tried this as follows
frown.gif
Please note, I am not a Computer graduate, and so have more ignorance than knowledge)
Private Sub Specimen_Number_LostFocus()
Dim db1 As Database
Dim rshepatitis_c As Recordset
Dim inthep_no As Integer
Dim hep_no As Integer
Set db1 = CurrentDb
Set rshepatitis_c = db1.OpenRecordset("HEPATITIS C")

rshepatitis_c.Close
db1.Close

[hep_no] = 1

While Not rshepatitis_c.EOF
rshepatitis_c.Edit
rshepatitis_c![hep no] = rshepatitis_c.RecordCount + 1
rshepatitis_c.Update
rshepatitis_c.MoveNext
Wend
End Sub
Where: HEPATITIS C IS A TABLE
HEP C IS IS THE FIELD( WHICH NEDDS TO BE UPDATED) IN TABLE
Any solutions? Alternates are welcomed as well!
 
DeepTrouble,

Couple of things with your code:
1. You do not want to close your table and db until after the code is run. So I would move this to after the Wend.

2. This code will run for every record in the table every time. So your numbers will change each time. Is this what you want?

Have you tried making the hep no an autonumber field? I have never put multiple autonumber fields in a table before so I am not sure if it will work. But if it does, this will eliminate the need for coding. Otherwise, I would pass the current record number to the procedure so that you are just updating the one record.

Let me know if you need additional help.

felicia.terry@asml.com or flea22@home.com
 

Users who are viewing this thread

Back
Top Bottom