Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2006
    Posts
    52

    Unanswered: Only enter existing values in text field

    Hi

    I have a form (only shows Patient Name) with subform that shows (BillID, PatientID, Sickness, Prescribtion, DoctorIDand Doctor Name) -
    Patient Name and Doctor Name are based on other tables (Patient & Doctor)
    ...
    I used combobox for the Patient Name so that I can only select from values already exist in table Patient-so that I can't enter names, only select...untill now everything is okay

    However, with Doctor Name-, I want to be able to write one of the doctor names that already exist, so I do NOT want new names to be entered....how can I do this without using a combobox? coz whenever I write a new name it is entered in the Doctor table..

    And IF i need to use combobox, how can I change the current text box to combobox with wizard? I know that I have to go to Format --> Change >combobox, but I want to see the wizard to guide me ... or how can i change properties so that it selects values I want

    Hope you understand me
    Thanks in advance

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You could use this (adapt the names to those of your database):
    Code:
    Private Sub Text_DoctorName_BeforeUpdate(Cancel As Integer)
    
        If DCount("[Doctor Name]", "Doctor", "[Doctor Name] = '" & Me.Text_DoctorName.Value & "'") = 0 Then
            MsgBox "This doctor name does not exist.", vbInformation, "Not found"
            Cancel = True
            Me.Text_DoctorName.Undo
        End If
        
    End Sub
    Have a nice day!

  3. #3
    Join Date
    Aug 2006
    Posts
    52
    Hi I would like to thank you for helping again, it works fine..
    I starting wondering, is there something wrong with my database relationship?
    because I noticed even when I enter a new doctor ID it accepts it, should a correct relationship bans entering a new doctor id in a bill table??

  4. #4
    Join Date
    Aug 2006
    Posts
    52
    .posted by mistake

  5. #5
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Quote Originally Posted by oakeyes View Post
    ... should a correct relationship bans entering a new doctor id in a bill table??
    Normally yes, if the relationships are correctly defined for the concerned tables.

    You're welcome by the way!
    Have a nice day!

  6. #6
    Join Date
    Aug 2006
    Posts
    52
    Thanks, i 'll study again my relationship and if can't solve the problem i'll post new topic with my file uploaded

  7. #7
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •