Difference between a command button and a 'label' button

L'apprentis

Redcifer
Local time
Today, 13:24
Joined
Jun 22, 2005
Messages
177
Hi, I have got a small problem and maybe someone could advise me.
I am creating a customised command button from a label button. The new button works fine but I can't apply the 'requery' function to it, if i do an error occures and i am being prompt to save the data first???? :confused: :


Code:
Private Sub Labelsearch_Click()
    Me!itemquery.Requery
End Sub

Private Sub Labelsearch_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.Labelsearch.SpecialEffect = 2
    Me.Labelsearch.BackColor = 255
    Me.Labelsearch.ForeColor = 10092543
    Me.Labelsearch.FontItalic = True
    Me.Labelsearch.FontBold = True
End Sub

Private Sub Labelsearch_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.Labelsearch.ForeColor = 255
    Me.Labelsearch.FontItalic = False
    Me.Labelsearch.FontBold = True
End Sub

Private Sub Labelsearch_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
   'Come back to initial state when button release'
   Me.Labelsearch.SpecialEffect = 1
   Me.Labelsearch.BackColor = 16373685
   Me.Labelsearch.ForeColor = 8388608
   Me.Labelsearch.FontItalic = False
   Me.Labelsearch.FontBold = True
End

If I create a command button with the wizard and assign the code :
Code:
me!itemquery.Requery
to the on_click event my form is working fine.
Why is his code is not working if I assign it to a label? :o
 
Last edited:
I'm not sure what you mean by

I am creating a customised command button from a label button.

I.e. Did you take a label control and change its type to Command Button?

Or did you just make a label have some events as though it were a button but it is really still just a label?

You might try this as an issue of edification: In HELP, look up Requery method (Control or Form Object). Then click on Applies To and see if the thing you are trying to do applies to the type of the object you named for the requery. Since you say it works one way and not the other, the odds are that the .Requery method works for the object. But it never hurts to check. Programmers should ALWAYS be skeptics for ANY language they use.

I have no idea why the same Requery method would work from one place and not work from the other, particularly since neither a label nor a command button have a .Value property. An event is an event regardless of which control event was fired. The only thing that should matter would be whether the object in question ever fired the event.

Here's a debugging suggestion only...

In your label event code, add one more to do something innocuous like add or subtract some constant to the forecolor or backcolor of the label or of some other visible feature. Maybe just make a label box and toggle its .VISIBLE property between TRUE and FALSE - or maybe do something else equally simple-minded like that. That way, you can know unequivocally that the event fired.

By the way, just because you can write code named XYZ_OnClick doesn't mean that it will respond to that event. If XYZ doesn't support the event you proposed, you can write the subroutine but Access won't ever call it. OnClick is usually a good bet, but it never hurts to check.
 
Thanks Doc Man, I am going to have a look at it. Your reply is gonna be quite helpfull. Just for the information: I just added some event to a label to make it look like a command so it is sill a label...
 
Except for coloring the background of a label...

Why would you want to use a label instead of a command button?
 
ghudson, it is an interesting way to have "secrets" in your form for debugging, particularly if the first thing they do is see if you are authorized to use the secret.

If it ain't a button, why click it? Except, of course, if you are "hiding" something.

I once used this feature to toggle visibility for some fields I used in tracking a search that retained some intermediate data and some statistics. Not everyone wanted to see that stuff, but when debugging, I sure as heck did.
 
but "unattached" labels do have five events to choose from
 

Users who are viewing this thread

Back
Top Bottom