Change value using OnClick

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lavdey
    New Member
    • Nov 2006
    • 3

    Change value using OnClick

    I am a beginner user of Access. I have developed a database for a non-profit to manage contacts. I would like to change a value in a record by using OnClick. For example, If the value is "Member" I would like to change it to "Past Member" by clicking a label "Convert to Past Member"

    Thanks
    Len
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32668

    #2
    You may find this link helpful (POSTING GUIDELINES: Please read carefully before posting to a forum).
    If our experts don't understand your question, or don't find enough information to give a meaningful answer to, they may well move along to another thread.
    We like to be helpful with answers where possible - the questions are down to you.

    Len,
    Your question is pleasingly brief, but doesn't give enough information.

    Comment

    • MMcCarthy
      Recognized Expert MVP
      • Aug 2006
      • 14387

      #3
      Originally posted by lavdey
      I am a beginner user of Access. I have developed a database for a non-profit to manage contacts. I would like to change a value in a record by using OnClick. For example, If the value is "Member" I would like to change it to "Past Member" by clicking a label "Convert to Past Member"

      Thanks
      Len
      Ok NeoPa is right but I'm going to make some assumptions.

      Firstly I assume that you are not trying to change the whole record but just one value in one field on the record. As I don't know the name of the control for that field I'm just going to call it txtMemberStatus for now.

      Although you can use a label for this purpose it's not normally done as users can click on labels accidently and not realise what they've done. Normally you would use a command button for this operation. Just drag one off the toolbar and cancel the wizard. For this example I will call it cmdChangeStatus .

      Then just add the code so it looks as follows:

      Code:
       
      Private Sub cmdChangeStatus_Click()
       
      	Me.txtMemberStatus = "Past Member"
       
      End Sub
      If you're not sure where to find this code. Open the properties window and click on the command button. Then under the event tab go down to On Click in the list. Make sure [Event Procedure] is selected and click on the button to the right.

      Comment

      • lavdey
        New Member
        • Nov 2006
        • 3

        #4
        Originally posted by mmccarthy
        Ok NeoPa is right but I'm going to make some assumptions.

        Firstly I assume that you are not trying to change the whole record but just one value in one field on the record. As I don't know the name of the control for that field I'm just going to call it txtMemberStatus for now.

        Although you can use a label for this purpose it's not normally done as users can click on labels accidently and not realise what they've done. Normally you would use a command button for this operation. Just drag one off the toolbar and cancel the wizard. For this example I will call it cmdChangeStatus .

        Then just add the code so it looks as follows:

        Code:
         
        Private Sub cmdChangeStatus_Click()
         
        	Me.txtMemberStatus = "Past Member"
         
        End Sub
        If you're not sure where to find this code. Open the properties window and click on the command button. Then under the event tab go down to On Click in the list. Make sure [Event Procedure] is selected and click on the button to the right.
        That's great. Just what I needed. Sorry for the lack of detail and clarity.

        Len

        Comment

        • MMcCarthy
          Recognized Expert MVP
          • Aug 2006
          • 14387

          #5
          Originally posted by lavdey
          That's great. Just what I needed. Sorry for the lack of detail and clarity.

          Len
          No problem. It's for your own sake really. The more detail you give the quicker and more accurate answer you're likely to get.

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            Another hack that I've used for this task in the past uses the often overlooked "Double-Click" event of a textbox. When a text box only has two possible values, this allows you to set a default value (when the field is empty) and "toggle" between the two values when the field is filled in.

            Code:
            Private Sub TextBoxEntry_DblClick(Cancel As Integer)
            	 If IsNull(Me.TextBoxEntry) Then
            		  Me.TextBoxEntry = "MEMBER"
            	 ElseIf Me.TextBoxEntry = "MEMBER" Then
            		  Me.TextBoxEntry = "PAST MEMBER"
            	 ElseIf Me.TextBoxEntry = "PAST MEMBER" Then
            		  Me.TextBoxEntry = "MEMBER"
            	 End If
            End Sub

            Comment

            • MMcCarthy
              Recognized Expert MVP
              • Aug 2006
              • 14387

              #7
              Originally posted by missinglinq
              Another hack that I've used for this task in the past uses the often overlooked "Double-Click" event of a textbox. When a text box only has two possible values, this allows you to set a default value (when the field is empty) and "toggle" between the two values when the field is filled in.

              Code:
              Private Sub TextBoxEntry_DblClick(Cancel As Integer)
              	 If IsNull(Me.TextBoxEntry) Then
              		 Me.TextBoxEntry = "MEMBER"
              	 ElseIf Me.TextBoxEntry = "MEMBER" Then
              		 Me.TextBoxEntry = "PAST MEMBER"
              	 ElseIf Me.TextBoxEntry = "PAST MEMBER" Then
              		 Me.TextBoxEntry = "MEMBER"
              	 End If
              End Sub
              Good workaround.

              I must admit I often overlook the double_Click myself as why two clicks when one will do but there are obviouly times when it would come in useful. I have to start thinking about it more.

              Mary

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32668

                #8
                Nice one ML.

                I sometimes use that in my Excel work - when I'm too lazy to add a button, or it's to toggle a single value in a column.

                Comment

                • missinglinq
                  Recognized Expert Specialist
                  • Nov 2006
                  • 3533

                  #9
                  as why two clicks when one will do
                  When doing this on a text box, you have to leave the single click alone so the user can "mouse" into the field if they want! The advantage of the method is that you save "real estate" that would be taken up with extra command buttons. I also use it for fields that need dates. I have a calendar control on the form that starts out being invisible. When the date field is double-clicked, the calendar becomes visible, the user picks a date, then the calendar becomes invisible again. Once again, a lot of space on the form is saved, and you're assured of the date being entered correctly!

                  Comment

                  • MMcCarthy
                    Recognized Expert MVP
                    • Aug 2006
                    • 14387

                    #10
                    Originally posted by missinglinq
                    When doing this on a text box, you have to leave the single click alone so the user can "mouse" into the field if they want! The advantage of the method is that you save "real estate" that would be taken up with extra command buttons. I also use it for fields that need dates. I have a calendar control on the form that starts out being invisible. When the date field is double-clicked, the calendar becomes visible, the user picks a date, then the calendar becomes invisible again. Once again, a lot of space on the form is saved, and you're assured of the date being entered correctly!
                    I definately have to think about it more. All my calendars end up on popup forms for this very reason.

                    Mary

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32668

                      #11
                      I never use calendars myself, but this sounds like a very intelligent way to handle them.
                      Good for you ML.

                      Comment

                      • lavdey
                        New Member
                        • Nov 2006
                        • 3

                        #12
                        I want to thank you all for the great suggestions. Problem solved.

                        Len

                        Comment

                        • MMcCarthy
                          Recognized Expert MVP
                          • Aug 2006
                          • 14387

                          #13
                          Originally posted by lavdey
                          I want to thank you all for the great suggestions. Problem solved.

                          Len
                          No problem Len

                          We're glad to help.

                          Mary

                          Comment

                          Working...