Disable button until field fillled

Eric the Viking

Registered User.
Local time
Today, 00:01
Joined
Sep 20, 2012
Messages
70
Seasons Greetings All

I have a minor niggle I am struggling to iron out. We have a database recording patient records and I am trying to stop people including me....!!! entering new records when the record already exists in the database.....it seems it is easily done after a hard day at the coal face!

I have an unbound txtbox named TextSurname (which will search on either surname or record number to populates a list box so exiisting records can be checked before hitting the enter new record button.

In the new record buttons code I have the following:


Private Sub OpeningFormPtDetails_Click()
On Error GoTo Err_ OpeningFormPtDetails _Click

Dim stDocName As String
Dim stLinkCriteria As String

If Me.TextSurname = "" Then
Me. OpeningFormPtDetails.Enabled = False
Else: Me. OpeningFormPtDetails.Enabled = True
End If

stDocName = "frm-patient details"
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.GoToRecord , , acNewRec

Exit_opening_form_pt_details_Click:
Exit Sub

Err_opening_form_pt_details_Click:
' MsgBox Err.Description
MsgBox "Check if the patient record already exists before entering a new patient", vbCritical
Resume Exit_ OpeningFormPtDetails _Click


End Sub

which is supposed to disable the button and encourage the user to check if the record exists first. It works fine except on opening the form containing the controls when the button will fire once to open the new record form afer which it is disabled until the TextSurname field has been filled.

Any ideas would be much appreciated.

Best

Eric
 
Thanks for the response

The controls are on a tab control sitting on an unbound form with several of the tabs having subforms displaying various things.

Putting the test code in onload/open/current of the unbound main form doesnt solve the problem and there doesnt seem to be an obvious event for the tab in question to use. Or have I missed something?

Best

Eric
 
Can you clarify what the problem is exactly?
 
I have a tab control on an unbound form and one of the tabs has a text box which populates a list box on the same tab with the patients having the surname I have typed in the text box. On this same tab I have a button which will open a form to enter a new patient. I want to disable this button until the user has searched to make sure the record doesnt already exist before entering a new record.

The code I posted earlier in the thread is supposed to disable the button for a new record until the text box has a name in it.

When the form is first opened the button is not disabled when I want it to be so a new record can be entered without first checking. Once the new record form has been opened once the code then seems to work ok disabling the button until the text box has a name in it.

So my problem is when the form is first opened.

Cheers

Eric
 
Thanks for your help have just tried a Bob Larson fix from another thread and it has sorted the problem:

Me.[opening form pt details].Enabled = (Len(Me.TextSurname & "") <> 0)

Obviously just didnt look hard enough and engage brain thoroughly .....

All the best for the New Year

Eric
 
Glad you got it sorted out.
 

Users who are viewing this thread

Back
Top Bottom