Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Aug 2001
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Disable command button in new record (Access97)

    Can anyone help please...
    I have several command buttons (go to next, delete) on a form (on a subform actually, but I don't think that will matter) which I want disabled in form view for a new record. This is to stop users from clicking the button and receiving an error message. Does anyone know how to do this? I have tried using a code expression (OnCurrent) which looks at the primary key and only enables the button if the primary key is not null, but I can't get it to work.
    Any suggestions?

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

    Re: Disable command button in new record (Access97)

    Instead of disabling the button and then reenabling it, why not just check in the code for NewRecord. Something like this:

    If Me.NewRecord = False Then
    'do whatever it was you were doing
    Else
    MsgBox "Command not available from an unsaved record."
    End If
    Charlotte

  3. #3
    New Lounger
    Join Date
    Aug 2001
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disable command button in new record (Access97)

    I have got it to kinda work by using this code on the OnCurrent event:
    command_button_name.Enabled = (Me.NewRecord = False)

    This is fine for Single Forms; however, I'm using Continuous Forms, so this code on the OnCurrent event disables the button in every record, whereas I want it to disable the button only in the new record (which of course appears at the bottom of the list before anything is entered into it. I don't want a user to be able to click the delete button in a new record (because this causes an error message). I'd prefer that the button was simply disabled in a new record. Do I need to attach this same code to a different event for the Form?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Disable command button in new record (Access97)

    You're running into a fundamental aspect of continuous forms that is confusing at first. A continuous form contains just a single set of controls that is displayed repeatedly by the use of smoke and mirrors; it doesn't contain an independent set of controls for each record, although it may seem so. The only things that are different are the data from each record. If you enable or disable a command button in the detail section, you will enable/disable the command button in every displayed record; if you lock a text box, you will lock it in every displayed record, etc. You may not like it, but that's the way a continuous form works.

    If you enable/disable the command button in the On Current event, it will work as you intend, but it's disconcerting to the end user to see a whole column of command buttons being enabled/disabled at the same time. That is why Charlotte suggested that you handle it in the On Click event procedure. Alternatively, you could move the command button to the header or footer section of the continuous form. That way, the user sees just one button, and its status will reflect the current record.

Posting Permissions

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