Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need help here to avoid duplicate entry!

I creat patient database which have patient ID field (text field) to enter patient No. a combination of charater and number(not an autonumber). I need a code to protect entering of a same ID when entering a new patient so that an existing patient ID should not be overwritten or there would be no same ID number.


Private sub ID_validate()

If (Eval("DLookUp(""[P_ID]"",""[rsPatient]"",""[P_ID]=frmPatient.[txtP_ID]"") Is Not Null")) Then
Beep
MsgBox "Patient ID already existed!!",
End sub

I tried this code but it doesnot work, in fact it seems the Eval and DLookUp function doesnot work at all in my program.

I would be very grateful if anyone help me in this problem.

Thank you.

Zela.

Comments

  • slickDevslickDev Member Posts: 9
    : I creat patient database which have patient ID field (text field) to enter patient No. a combination of charater and number(not an autonumber). I need a code to protect entering of a same ID when entering a new patient so that an existing patient ID should not be overwritten or there would be no same ID number.
    :
    :
    : Private sub ID_validate()
    :
    : If (Eval("DLookUp(""[P_ID]"",""[rsPatient]"",""[P_ID]=frmPatient.[txtP_ID]"") Is Not Null")) Then
    : Beep
    : MsgBox "Patient ID already existed!!",
    : End sub
    :
    : I tried this code but it doesnot work, in fact it seems the Eval and DLookUp function doesnot work at all in my program.
    :
    : I would be very grateful if anyone help me in this problem.
    :
    : Thank you.
    :
    : Zela.
    :
    :



  • slickDevslickDev Member Posts: 9
    : : I creat patient database which have patient ID field (text field) to enter patient No. a combination of charater and number(not an autonumber). I need a code to protect entering of a same ID when entering a new patient so that an existing patient ID should not be overwritten or there would be no same ID number.
    : :
    : :
    : : Private sub ID_validate()
    : :
    : : If (Eval("DLookUp(""[P_ID]"",""[rsPatient]"",""[P_ID]=frmPatient.[txtP_ID]"") Is Not Null")) Then
    : : Beep
    : : MsgBox "Patient ID already existed!!",
    : : End sub
    : :
    : : I tried this code but it doesnot work, in fact it seems the Eval and DLookUp function doesnot work at all in my program.
    : :
    : : I would be very grateful if anyone help me in this problem.
    : :
    : : Thank you.
    : :
    : : Zela.
    : :
    : :
    :
    : First what database system do you use.If is Access then you can do somthing simple:
    1.Open the Access database , open the Table in desing view and to the properties window set property INDEXED=Yes(Dublicates Not Allowd). So if you make dublicate entry an error will appears(Error Number: -2147217887).If you want to trap the error you can use a simple code:
    Place this code line before Recordset.Update: On error Goto Dublicate_Error
    Place this Line After RecordSet.Update:
    Dublicate_Error:
    if err.number=-2147217887 then
    msgbox "Your msg" 'or you can add code withou msgbox.
    2.Use only code:
    Private sub ID_validate()
    rsPatient.MoveFirst
    Do Until rsPatient.EOF
    If txtP_ID=rsPatient!P_ID then
    MsgBox "Patient ID already existed!!"
    Exit Do
    end if
    rspatient.Movenext
    Loop
    I hope that this will help you!
    :
    :



Sign In or Register to comment.