**Please help*** Hiding Command buttons based on form function

G

Guest

Hello All.

Hope you are having a good easter, unfortunatly i have a project to deliever
by tuesday and i need a little help.

I have a table called tblUsers, which contains all user info needed for
access to the DB. I have a form which is linked to this called frmUserAdmin,
which is the front end i intend to use to manage all user info.

I have control buttons on the bottom (in the form footer) cmdFirst, cmdPrev,
cmdNext, cmdLast, cmdAdd and cmdExit.

I have other buttons on other forms which will open the frmUserAdmin. What i
want to do is control which of the command buttons are available to the user
based on how the frmUserAdmin is used. I.e. if i want to add a user i have a
button which opens the from in add mode. As such i want to disable the next,
prev, first and last record navigation buttons, so the user only has the
option to add a new user. Likewise i have another button on another from
which will open frmUserAdmin in read only mode, where i want them to have
access to all command buttons except cmdAdd (so they cant add people). I hope
this makes sence.

Here is the snipet of code i am using,

Private Sub cmdAddUserAdmin_Click()
On Error Goto Err_cmdAddUserAdmin_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmUserAdmin"
DoCmd.OpenForm stDocName, , , stLinkCriteria
**See Below***
Exit_cmdAddUserAdmin_Click:
Exit Sub

Err_cmdAddUserAdmin_Click:
MsgBox Err.Description
Resume Exit_cmdAddUserAdmin_Click

End Sub


** Now i have tried the following to hide the cmdAdd,

1. Me!cmdAdd.Visible = False
2. Me!cmdAdd.Enabled = False

I know i could create 2 forms, one for adding and one for viewing but i know
this can be done in code. Please help.

Kind regards
 
A

Arvin Meyer [MVP]

Have you tried using OpenArgs (the last argument in the OpenForm method)? I
would add a value like the word "Hide" to your OpenForms statement:

DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd, acWindowNormal,
"Hide"

I only use the word "Hide" because it makes the code somewhat
self-documenting. Now in the form's Open event check OpenArgs and hide the
controls as desired:

Private Sub Form_Open(Cancel As Integer)
If Me.OpenArgs = "Hide" Then
' Do your thing
End If
End Sub
 
G

Guest

Hi ATA,

You could use Arvin's 'openargs' solution with a select case statement and
have different cases depending on which form was the originating form. For
example, if you come from the form that has the button to open your
frmauseradmin in 'readonly' mode, that could be:

Case "readOnly" 'where you make the openargs = "readOnly" in the form with
the command button that opens frmuseradmin

Another form might open the new form in add mode and be Case "Add"

Also, you can't use 'Me' in one form to accomplish things in another form,
so your Me!ctl.visible code you posted isn't going to work when the ctl is in
the new form that pops up. Me refers to the current form....the form where
the 'Me' code is actually written.

CW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top