Hiding Buttons on a form

mrh

Registered User.
Local time
Today, 21:14
Joined
Oct 11, 2008
Messages
14
Morning all!

Question from a novice I'm afraid.

I have a simple form I am using for employees to "clock-in" and "clock-out" for their weekly timesheet.

When they select their name, the form shows them if they are currently "clocked-in" or "clocked-out".

If they are "clocked-in" I only want them to see the "clock-out" button and vice-versa.

I guess I can acheive this with the "Visible" parameter on the button control.

The bit I am struggling with is the coding.

I have very little experience of VBA and tend us macros to make up for this!

How do I write a few lines of VBA to do what I need?

I can call it from the "On Update" event when they have selected their user name - so it will then know if the person is "Clocked-in" or "clocked-out". But its the actual code that has me stumped!

At the moment I have:-

"Private Sub Command26_Click()
Me.ClockOut.Visible = No
End Sub"

attached to a seperate button for testing, but it doesn't work!

The form is called "ClockCard" and the button I'm trying to hide is called "ClockOut".

Please can someone point me in the write direction to get the simple test code working, then I can progress to the "If" functionality I need?

Many thanks


Matthew
 
Try this:

In the after Update event of your "Name Select" put the following:

Code:
if me.yourcontrol = "Clocked-In" then
me.clockout.visible = true
me.clockin.visible = false
else
me.clockout.visible = false
me.clockin.visible=true
end if

Where yourcontrol is the control that tells whether the employee is clocked in or not
 
The code should be in the OnCurrent event and called in the AfterUpdate event
 
Many thanks for the replies.

I'll try them out later on and report back.

Much appreciate the effort.

Thanks


Matthew
 
The code should be in the OnCurrent event and called in the AfterUpdate event

OK.

Now that's confused me.

I understand the first bit "The code should be in the OnCurrent event". So I add the code as a procudure in the OnCurrent event parameter.

"and called in the AfterUpdate event"

How do I do this? Enter the same code as in the OnCurrent? Or can I link/reference back to it?

Thanks for your patience,

Matthew
 
in the After Update event just insert "Form_Current" on a new line. This will call and execute the code in the OnCurrent
 
Another complication! Sorry!

The control I am looking to check to see if it is "Clocked In" or "Clocked Out" is actually on a subform called Status1.

I've tried:-

Private Sub SelectedOperator_AfterUpdate()
Refresh
If Me!Status1.Clockcard!CalcStatus = "Clocked-In" Then
Me.ClockOut.Visible = True
Me.ClockIn.Visible = False
Else
Me.ClockOut.Visible = False
Me.ClockIn.Visible = True
End If
End Sub

But it gives a 438 error on the line

If Me!Status1.Clockcard!CalcStatus = "Clocked-In" Then

I've tried lots of options, and looked at:

http://www.mvps.org/access/forms/frm0031.htm


But I'm still missing something!

Many thanks

Matthew
 
What you need is

Me.YourSubformContainerName.Form.CalcStatus

Not sure what your subform container name is (sometimes it is the name of your subform and sometimes it might be something else, depending on how you set it up). So, you make sure that the subform container name is used instead of the subform itself. Also, you need the .Form. (as written) between the subform container and the control so that Access knows that you are going to be referring to something on the actual subform and not on the subform container.
 
That was great.

Many thanks!

All working now.

Everyone's help much appreciated.

About to post a new thread about using vba to add records! Here



Matthew
 
Last edited:

Users who are viewing this thread

Back
Top Bottom