Strange error occur when one command playing several roles

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • StephanieCat
    New Member
    • Mar 2007
    • 5

    Strange error occur when one command playing several roles

    I am designing a 2000 format database in 2003.

    In a form, I use two buttons to serve several circustances:
    1. Button1.caption ="New record" Button2.Caption ="Edit record"
    After click Button1, data entry appears. Button captions change into:
    2. Button1.Caption ="Save Record" Button2.Caption ="Cancel"
    If I select Button2 in first occassion to edit the current record, Button captions change into:
    3. Button1.Caption ="Save Changes" Button2.Caption ="Undo changes"

    In this way, every button has 3 functionalities to execute. To choose the right function, I judge by button captions.
    --------------------------------------------------
    Code:
    Private Sub Button1_Click()
    
    Select Case Me.Button1.Caption
    Case "New Record"
    ....
    Case "Save Record"
    ....
    Case "Save Changes"
    ...
    End Select
    End Sub
    -----------------------------------------------

    It works on my pc. But it does not once the DB is put onto server and accessed from another PC (Access 2003). It seems the problem is caused by selecting its caption.

    I am really confused. Could someone help me with this?
    Last edited by NeoPa; Mar 23 '07, 01:43 PM. Reason: Tags
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    I can't help much I'm afraid, as I use Access 2K at work and I've never come across this problem before. Using technical parlance this is a 'BITCH'.
    To get around it, if you're not currently using the .Tag property of the CommandButton, set that to match the .Caption and then use that in your Select Case code.
    Check compilation of your code though as I'd be surprised if you could change the .Caption but were unable to read it :s

    Comment

    • MMcCarthy
      Recognized Expert MVP
      • Aug 2006
      • 14387

      #3
      What error message are you getting Stephanie?

      Comment

      • StephanieCat
        New Member
        • Mar 2007
        • 5

        #4
        Thank you for your help guys!

        I got around the problem by adding a form-wise variable to store the "add new" or "edit" status. It is so weird. I think VBA doesn't like any spaces or "-" in the caption; otherwise it will work.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          As long as you're sorted Stephanie.
          I won't pretend to understand what caused your problems.

          Comment

          Working...