Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2006
    Location
    Lincoln, UK
    Posts
    24

    Unanswered: VBA Help required

    Ok, it's late, and my brain has switched off.

    I have a form with a number of buttons on it. I want to change the image from flat to Etched when it is pressed. As the same code applies to each button, excpet it's name, I want to set a variable containign the button name, and pass that the another peice of code which contains the actual button down code. So I came up with this: -

    Private Sub Button2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim stButtonNo As String
    stButtonNo = "Button2"
    ButtonDown

    End Sub

    Private Sub ButtonDown()
    ' Special Effect 3 shows effect of Etched
    ' If you copy the code to another image then change the Image name in the line below
    stButtonNo.SpecialEffect = 3
    End Sub

    And yes I know I've nicked the basic code from elsewhere.

    The problem is, when I click on the button, I get the error "Run time error '424' Object required, and the Debug points to the 'stButtonNo.SpecialEffect = 3' code.

    Where am I going wrong? What am I missing here?

    Thanks in advance.

    Das_EEjit

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    If you go to the vb help on the SpecialEffect Property, and click the Applies To blue words at the top, you will see that this property does not apply to command buttons.

    But if you were to do this to, say a text box, here's some code that kinda gets at what you want. It's for a form called Form1, with a text box called TxtBox1 who's special effect is changed bewtween two settings with the On Click Event of two buttons (Command0 and Command1).
    PHP Code:
    Private Sub Command0_Click()

    Call ButtonUp("TxtBox1")

    End Sub

    Private Sub ButtonUp(strButtonName As String)

    Forms("Form1").Controls(strButtonName).SpecialEffect 0

    End Sub

    Private Sub Command1_Click()

    Call ButtonDown("TxtBox1")

    End Sub

    Private Sub ButtonDown(strButtonName As String)

    Forms("Form1").Controls(strButtonName).SpecialEffect 4

    End Sub 
    Me.Geek = True

  3. #3
    Join Date
    Aug 2006
    Location
    Lincoln, UK
    Posts
    24

    VBA Help required

    Thanks Nick, I'll try it tomorrow.

    It's not actually a command button, it's an a small image acting as a comamnd button. There is other code in the OnClick event that does something else.

    Regards
    Das

  4. #4
    Join Date
    Aug 2006
    Location
    Lincoln, UK
    Posts
    24
    That's command, not comamnd duh

    Das

  5. #5
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Any reason you can't use a Toggle button for this? Just add the image to the button.

  6. #6
    Join Date
    Aug 2006
    Location
    Lincoln, UK
    Posts
    24

    VBA Help required

    DC - By it's own definition, a Toggle button is either on or off, and it keeps it's state when switching between forms.

    What I was trying to do was to simulate a switchboard page and use an image instead of the dreary grey button.

    DC's suggestion reminded me that I can choose my own image to show on a command button, stupid me. Now you know why I'm called Das_EEjit

    Many thanks to nckdryr and to DC for the suggestions.

    Regards
    Das

  7. #7
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Maybe you are sorted on this now but in case you aren't....

    There is an example of a nice image-simulating-buttons here:
    http://www.dbforums.com/showpost.php...80&postcount=3

    The original code is not mine. It was posted by one of our contributers but I can't remember who. If anyone knows who posted it (or you are the original poster) please let me know and I will credit the source properly.

    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

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