hide button code error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Why is the following line not working:
Me.cmdnew = False

This line is on the following code:

Private Sub Form_Current()
If Me.Recordset.RecordCount > 1 Then
Me.NavigationButtons = True
Me.cmdnew = False
Else: Me.NavigationButtons = False
End If

End Sub
 
If you are trying to hide the button, use its Visible property:

Me.cmdnew.Visible = False
 
Thank you for your reply BruceM, but it is still not working.
I got the message:
Compile error:
Method or data member not found.


"BruceM" escreveu:
 
Do you have a command button named cmdnew? If so, when you start typing
that line of code does cmdnew show up as one of your choices after you type
Me plus the period? If the answers to those questions are yes and no, try
deleting cmdnew, compact and repair the database (Tools > Database Utilities
Compact and Repair, then make a new cmdnew.
By the way, what are you trying to do? It looks as if when there is more
than one record you want to disable the built-in navigation buttons. That
means that if there is more than one record the user can't navigate through
the records. However, if there is just one record there is no need to do
anything other than add a new record. If you want a different appearance
when you are at the first record, try If Me.CurrentRecord > 1. If you want
users to be able to enter data but not look at existing records, you could
set the form's Data Entry property to Yes, although I believe they will be
able to look at just-entered records, in which case some variant of your
code could be useful. But why not just have a cmdNew (to add a new record)
and no other navigation buttons?
 
I do not have a command button named cmdnew. I thought this was the name of
the new command on the navigation buttons.

I want to disable navigation buttons, except when the form is filtered.
There are 5 navigation buttons: previous, next, first, last and new.
Even when the form is filtered, I want the “new†navigation button to be
disabled, because I have, indeed, a make new button.
So, my idea is: when the form is filtered and there is more than one record,
show all navigation buttons except the new one.



"BruceM" escreveu:
 
The default New Record button does not have a name you can identify with
code, unless there is some elaborate code that can do the trick. It's all
or nothing with the Navigation Bar.

Here is some code I use for custom navigation buttons. This is designed to
be placed in the form's Current event. Laterly I have been using a variant
of the code in a standard code module so that I don't need to add the code
to the Current event each time I create a form, but this is simpler to
implement.

'Inserts current record number and total number of records

Dim strCurrent as String, strTotal as String
strCurrent = Me.CurrentRecord
Me.RecordsetClone.MoveLast
strTotal = Me.RecordsetClone.RecordCount

If Me.NewRecord Then
Me.txtCounter = "New Record"
Else
Me.txtCounter = strCurrent & " of " & strTotal
End If

'Enable navigation buttons only when there are records available
Me.cmdPrev.Enabled = Not Me.CurrentRecord = 1
Me.cmdFirst.Enabled = Not Me.CurrentRecord = 1
Me.cmdNext.Enabled = (Me.CurrentRecord = 1 And Me.Recordset.RecordCount
Or Me.CurrentRecord < Me.Recordset.RecordCount
Me.cmdLast.Enabled = (Me.CurrentRecord = 1 And Me.Recordset.RecordCount
Or Me.CurrentRecord < Me.Recordset.RecordCount

This assumes an unbound text box named txtCounter, and four navigation
buttons: cmdFirst, cmdPrev, cmdNext, cmdLast. You would probably have
cmdNew also.
The code in the Click event for cmdFirst is:
DoCmd.GoToRecord , , acFirst
Substitute acPrevious, acNext, acLast, and acNewRec as needed for the other
command buttons.

You can hide the buttons, leave them out, or whatever you choose. This
should give you a starting place. Play around with it for a while, and post
back if you have more questions about how to implement your particular
requirements.
 
@BruceM

Had to comment that I found your code and explanation very helpful. I
immediately knew how it would apply to my situation also.

Thanks!
 
Back
Top