When data is entered, it blocks out other fields?

jammy01

New member
Local time
Today, 11:34
Joined
Jan 2, 2008
Messages
8
Hi,

I need some help!

In my form I have 2 toggle buttons and what I want to happen is when one is selected other fields are blanked out (i.e. you can not add any data in those fields).

I am thinking it must be some validation rule but I don't think you can link fields?

Anyone got any ideas?

Thanks a lot!
 
Can't you just add an Event Procedure for the radio button so that On Click that makes the required text boxes, ListBoxes etc locked/not enabled? As in....

Forms!Frmwhateveritscalled!TxtBoxwhatever.Enabled=False
 
Can't you just add an Event Procedure for the radio button so that On Click that makes the required text boxes, ListBoxes etc locked/not enabled? As in....

Forms!Frmwhateveritscalled!TxtBoxwhatever.Enabled=False

Thanks for the reply

The radio button is named - "Occured on patrol"

One of the fields I want locked is named - "Call from"

So what should I write as everything I've tried - I get a error message that it doesn't meet the validation rule defined?

If you could tell me what to write I'll be most grateful!

Thanks a lot!
 
Thanks for the reply

The radio button is named - "Occured on patrol"

One of the fields I want locked is named - "Call from"

So what should I write as everything I've tried - I get a error message that it doesn't meet the validation rule defined?

If you could tell me what to write I'll be most grateful!

Thanks a lot!

Are you able to cut and paste the code you have for the form, Including the procedure for the radio buttons? Without the whole picture it's hard to quote the exact coding. From the Visual Basic Editor
 
Are you able to cut and paste the code you have for the form, Including the procedure for the radio buttons? Without the whole picture it's hard to quote the exact coding. From the Visual Basic Editor


How do I do that? I can't seem to get the VBE to show the coding for the whole form?

It is only a simple tab form I have created?
 
On the left hand side of the Visual Basic editor is a list of forms and reports, double click the form that you are interested in and a window should appear with all of your subs code.
 
You want to create an 'Event Procedure' under 'After Update Event' for that Toggle Button.

See the following code example:

Code:
Private Sub tglExample_AfterUpdate()

If Me.tglExample = -1 Then

    '-1 = Toggle Button is Pressed
    Me.txt_Empl_Name.Enabled = True

Else

    '0 = Toggle button isn't pressed
    Me.txt_Empl_Name.Enabled = False

End If

End Sub



As a side note you may not to make your form Control Names like this:

"Occured on patrol"

"Call from"

Your going to run into problems that way. Change the Control name to something without spaces or with underscores. I would also suggest using a Name Convention when you name your database objects and controls. It makes it easier to program and for others to debug your code.

Here is a list of commonly used naming conventions...
http://www.mvps.org/access/general/gen0012.htm

Using your example above you can name your Toggle Button as:

tglPatrol or tgl_Patrol

Your Text Box could be:

txtCallFrom or txt_Call_From
 
On the left hand side of the Visual Basic editor is a list of forms and reports, double click the form that you are interested in and a window should appear with all of your subs code.

I still can't get the full code? It has the drop down at the top listing all the fields in the form?

What is it you need to know to help me with the event code?
 
Telecom's answer is a good one (although no error handling in the sub ;o) )

Are you able to initiate an Event Procedure Jammy, does that make sense or is it like DoubleDutch? Sorry to ask, but you may need to read up on Event Procedures first?
 
Ok, I understand what Telcom has said (thanks by the way)

I have changed my field names (i.e. Occured & Call)

This is what I have wrote

Private Sub Toggle166_AfterUpdate()

If Me.Toggle166 = -1 Then

'-1 = Toggle Button is Pressed
Me.Call.Enabled = True

Else

'0 = Toggle button isn't pressed
Me.Call.Enabled = False

End If
End Sub

But I am still getting a error. The error is the .Enabled parts

When I delete the .Enabled the only option it gives me is .Value

Thus, when in the form I select the toggle "Occured" it enters -1 in the "Call" field, instead of blocking it out?
 
Ya, I did forgot to add the error handling...opps.

Here is the code with Error handling:

Code:
Private Sub tglExample_AfterUpdate()

'Sets the Toggle Button
'-----------------------------------------------------------------
On Error GoTo Error_Handler


If Me.tglExample = -1 Then

    '-1 = Toggle Button is Pressed
    Me.txt_Empl_Name.Enabled = True

Else

    '0 = Toggle button isn't pressed
    Me.txt_Empl_Name.Enabled = False

End If

Exit_Procedure:
    'Error Cleanup
    On Error Resume Next
    DoCmd.Hourglass False
    DoCmd.SetWarnings True
    varReturnVal = SysCmd(acSysCmdClearStatus)
    
    Exit Sub

Error_Handler:
    MsgBox "An error has occured in this application. " _
    & "Please contact the database administrator and " _
    & "tell them this information: " _
    & vbCrLf & vbCrLf & "Error Number " & Err.Number & ", " _
    & Err.Description, _
    Buttons:=vbCritical, Title:="Database Title Here"
    
    Resume Exit_Procedure
    Resume
'-----------------------------------------------------------------
'End of Code

End Sub
 
Jammy do you have an example of your form or screenshot of it in design mode?
 
Jammy do you have an example of your form or screenshot of it in design mode?

Here you go:

12.jpg


What I want is when you select "Occured" the following fields are blocked orr blanked out ("Call", "State Other", "Date of Call", "Time of Call" & "Time of Actual Incident")

Anymore ideas?

Cheers
 
I think I know what is happening here. It looks like you have the wrong name for your control in your code. You may be using the Label Name and not the Control Name.

A Control is a text box, combo box, toggle button, etc.

When you name your control you right click the control (not the Label) and select Properties.

A popup box will come with multiple tabs. In the 'Other' Tab your first option is 'Name'.

That is the Control Name and the one you use in your code.

For your combo box with the Label "Call" change the name on the control name to "cboCall".

I would change the Toggle Button control name too; that way it's easier to go back and figure out what you've programmed. (See my first thread on naming conventions.)

Change it to "tglOccured"

Now change your code as follows:



Code:
Private Sub tglExample_AfterUpdate()

'Sets the Toggle Button
'-----------------------------------------------------------------
On Error GoTo Error_Handler


If Me.tglOccured = -1 Then

    '-1 = Toggle Button is Pressed
    Me.cboCall.Enabled = True

Else

    '0 = Toggle button isn't pressed
    Me.cboCall.Enabled = False

End If

Exit_Procedure:
    'Error Cleanup
    On Error Resume Next
    DoCmd.Hourglass False
    DoCmd.SetWarnings True
    varReturnVal = SysCmd(acSysCmdClearStatus)
    
    Exit Sub

Error_Handler:
    MsgBox "An error has occured in this application. " _
    & "Please contact the database administrator and " _
    & "tell them this information: " _
    & vbCrLf & vbCrLf & "Error Number " & Err.Number & ", " _
    & Err.Description, _
    Buttons:=vbCritical, Title:="Database Title Here"
    
    Resume Exit_Procedure
    Resume
'-----------------------------------------------------------------
'End of Code

End Sub
 
It worked.......... THANKS A LOT TELECOM!!!!!!!!!!

I just had to swap the True & False!


I would have never worked out how to do this - nice one!!!!!!!!!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom