Results 1 to 8 of 8
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code: frmHeader - other buttons

    Creating other command buttons
    ==============================

    Create three other command buttons. Call them cmdSave, cmdRefresh and cmdCancel.

    Change the captions to be "Save", "Refresh" and "Cancel".

    Make the program code of cmdCancel_Click look just like the program code of cmdOK_Click:

    <pre>Private Sub cmdCancel_Click()
    ' Procedure : cmdCancel_Click
    ' Description: What happens when the user clicks on the Cancel button.
    ' By: Chris Greaves Inc.
    ' Inputs: None
    ' Returns: None
    ' Assumes: Nothing
    ' Side Effects: None.
    ' Tested: By a call from the form.
    Unload Me ' "Me" is a nice VBA-generic name for whatever form we happen to be in.
    End Sub
    </pre>


  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Code: frmHeader - other buttons

    Just remember, this isn't the syntax you use with Access forms, only Microsoft forms.
    Charlotte

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code: frmHeader - other buttons

    Eh? Could you please elucidate?

    Access is a Microsoft product, right? But you're suggesting that there's a difference between GUI forms in Word (where I mostly live) and Access (where I think you hang out).

    What is there about a simple "Unload Me" that wouldn't work in Access?

    Thanks for any tips

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Code: frmHeader - other buttons

    Access forms are NOT the same as MS forms in other Office apps and VB. Access forms are created to be bound to data rather than having to use data controls or some such mechanism, and the properties of the forms and their controls are somewhat different from those of MS forms.

    As for Unload Me, it doesn't exist in Access and will cause a syntax error. In Access, you close a form, rather than doing an unload, and the syntax is DoCmd.Close, which applies to the active container, form or report. If you want to make sure you close the right one, it's DoCmd.Close acForm, Me.Name.

    See why I keep pointing out that Access is different? [img]/w3timages/icons/grin.gif[/img]
    Charlotte

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code: frmHeader - other buttons

    >In Access, you close a form, rather than doing an unload,

    Thank you.

    This rather strengthens the argument for the pedant in me that tends to write a 1-line cover function for every feature of the language.

    Writing myself a function like

    <pre>Sub CloseIt(frmMe as form)
    Unload frmMe
    End Sub
    </pre>


    would make for an easier migration to Access, since I'd have a slew of tiny cover functions that would crop up as needing adjustment.

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Code: frmHeader - other buttons

    It might be useful elsewhere, but I'm not sure it's worth the effort for migration to Access, since you would also have to recreate all your forms and reports there and their properties are different in Access.

    As an example, the Text property so beloved of VBA programmers doesn't work the same way in Access. There, you can only get to the Text property of a control while the control has the focus. Otherwise, you have to refer to the Value property, which is the default property of a control that can hold data in Access.
    Charlotte

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code: frmHeader - other buttons

    So in Word97/VBA i should use "value" rather than "text" in an effort to make my VBA code more generally useful?

    Most of my VBA has been in Word97, so I'm quite insular as regards other apps, and that's not a good thing.

    O really treasure these insights into another world.

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Code: frmHeader - other buttons

    I rarely work in Word code these days, so I can't recall whether it works but I suspect not. I think Text is the default property in Word. In Access, the Text property is used differently and in fact can differ from the Value property, since Text is what is displayed, which may not be the same as the underlying value.
    Charlotte

Posting Permissions

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