Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    May 2001
    Location
    indiana
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    copying code issues (access 97)

    hi all,
    i have a gripe about copying and pasting code and hope that someone can help me out...

    sometimes i will copy and paste code from one form to another or within the same form. if i copy an event procedure and paste it within the same form (changing instances of one control with another in the new code). some times the code works without problem. other times, since i didn't select the control and event from the drop down boxes, it does not read that code when that event occurs.

    one particular example:
    i have code

    Private Sub lblLogin_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    'VBA code here

    End Sub

    which works fine. if i copy this and change "lblLogin_MouseMove" to "lblClose_MouseMove" the mousemove event never triggers for lblClose. any suggestions??

    thanks in advance <img src=/S/confused.gif border=0 alt=confused width=15 height=20> <img src=/S/grovel.gif border=0 alt=grovel width=31 height=23>

  2. #2
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    Faifax, Virginia, USA
    Posts
    542
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: copying code issues (access 97)

    The stuff to copy is the guts.

    The shell has to be generated from the event. On the form properties, select the label, select the event, and generate the shell, which also associates the name of the thing with the action. [That's what youre missing when you merely invent a name.]

    Copy n paste guts to suit.

  3. #3
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: copying code issues (access 97)

    Hi,
    I suspect that you need to add '[Event Procedure]' (without the quotes) to the On Mouse Move property of the control so that it 'knows' there's an event procedure assigned to it. (I'm assuming that your example does not actually refer to a label control, unless it's a free standing one?)
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  4. #4
    2 Star Lounger
    Join Date
    May 2001
    Location
    indiana
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: copying code issues (access 97)

    thanks guys. i think the problem WAS in that it didn't know an [event procedure] occurred. i will try this and see if it works. by the way, the code example does refer to a label control. i seem to have more visual control over a label than a command button, so i just set label_click to whatever i need it to do. i know this probably isn't the best way to do things, but a command button's visual effects are so limited.

    thanks again

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

    Re: copying code issues (access 97)

    You don't actually have to generate the shell from the event, but you do have to set the event properties to [Event Procedure] so that Access knows it should execute the code when the event fires.
    Charlotte

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

    Re: copying code issues (access 97)

    Nothing wrong with using a Label instead of a command button. I have a demo database that simulates buttons in several ways with nary a button in the app. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> On the other hand, you can't make a label the default or cancel control when Enter or ESC is pressed. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15> I'm not big on visual effects anyhow.
    Charlotte

  7. #7
    2 Star Lounger
    Join Date
    May 2001
    Location
    indiana
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: copying code issues (access 97)

    yes, there are drawbacks to using labels, but for this particual form those drawbacks were not really an issue. my background is in the architectural field, so naturally, i make visual appeal one of the most important things in my apps. in fact, i will make my forms look like i want them to look, then get them to work correctly. perhaps not the best way to approach it, but it makes me feel like i am accomplishing what i intend to, sooner than making it work first. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

Posting Permissions

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