Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    RasterImage is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2011
    Location
    UK
    Posts
    34

    Hide new record in form

    Hello,

    I have a form with multiple records. Many of the fields have default values, so when viewing the form, it's easy to mistake the 'new' record for a saved record.

    Is there any way of making the new record invisible until the focus is moved to it, whether by clicking the 'new record' triangle in the status bar, or by tabbing to it, please?

    Thanks.

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    In the form's On Current Event set the form's Allow Additions property to False:

    Code:
    Me.AllowAdditons = False
    Have a button on the form which says ADD NEW. Put this code behind it:

    Code:
    Me.AllowAdditions = True

  3. #3
    RasterImage is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2011
    Location
    UK
    Posts
    34
    Hey, that works alright. Thanks boblarson. No way of getting it to do it without the button? Or of hiding the new record without adding another button?

  4. #4
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    You might be able to put it in the Form's After Update event (setting the allow additions to true).

  5. #5
    RasterImage is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2011
    Location
    UK
    Posts
    34
    Yes, I'm happy now. I'm sticking with the button, I've decided I like it, and set the form to dis-allow additions After Update. Thank you so much for your simple and elegant solution.
    All I want now, for complete Access pleasure, is if clicking the 'ADD NEW' button could also move the focus to the first field of the new record? I'm sure that must be possible, but no idea how...

  6. #6
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by RasterImage View Post
    All I want now, for complete Access pleasure, is if clicking the 'ADD NEW' button could also move the focus to the first field of the new record? I'm sure that must be possible, but no idea how...
    In the code for that button you can use

    Me.YourControlNameHere.SetFocus

  7. #7
    RasterImage is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2011
    Location
    UK
    Posts
    34
    I took your suggestion - I now have the following

    Code:
     
    Private Sub cmdAddNew_Click()
    DoCmd.Save
    Me.AllowAdditions = True
    Me.NextDate.SetFocus
    DoCmd.GoToRecord , "", acNewRec
    End Sub
    I found that without "DoCmd.Save", I'd get an error if I clicked the button when I'd updated a field but not saved it. "You can't go to the specified record."
    But with the save, it saves the whole form, which takes time, two or three seconds.
    It's never easy, is it? You sort me out, but other problems arise.

    Is there another way of avoiding the error?

  8. #8
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Don't use

    DoCmd.Save

    That has NOTHING to do with Records. That has to do with DESIGN CHANGES to the form.

    It should be

    Code:
    Private Sub cmdAddNew_Click()
       If Me.Dirty Then Me.Dirty True
       
       Me.AllowAdditions = True
       Me.NextDate.SetFocus
     
    DoCmd.GoToRecord , "", acNewRec
     
    End Sub
    The above syntax will only attempt to save a record if there is something in need of saving.

  9. #9
    RasterImage is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2011
    Location
    UK
    Posts
    34
    Aargh, it still doesn't work.

    The code you gave me just gives an error.
    I substituted "Me.Dirty = True", instead of just "Me.Dirty True".

    Now I sometimes get:

    Run-time error '7768':
    In order to change data through this form, the focus must be in a bound field that can be modified.
    So sorry to keep pestering you with this. I didn't think it would be so tricky or I might not have started, but it would be really nice to get this right!

  10. #10
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Sorry, I guess I had a bad day (not the only messed up code I issued yesterday)

    It should be:

    If Me.Dirty Then Me.Dirty = False

    with the equals sign, but FALSE not TRUE.

  11. #11
    RasterImage is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2011
    Location
    UK
    Posts
    34
    Yes! It works. It's everything I dreamed of. Thank you so much.

  12. #12
    jobrien4 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    20
    I am trying to use this code but am running into some problems.

    I have frm_Parts with a button on it that launches frm_Bevel. frm_Bevel is the form I want to hide the New Record row, and it is a multiple items form that has a tabular layout.

    So the OnCurrent for frm_Bevel info has the following code:
    Me.AllowAdditions = False

    I also have an AddButton where the OnClick:
    Me.AllowAdditions = True
    DoCmd.GoToRecord , , acNewRec

    The new record is hidden when the form loads, but when I hit the Add New button, nothing happens. The add button was working fine before I tried to hide the New Record. Any ideas?

  13. #13
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    frm_Bevel isn't a subform (sitting on frm_Parts) is it?

    What code are you using to open frm_Bevel if it isn't a subform?

  14. #14
    jobrien4 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    20
    DoCmd.OpenForm "frm_BevelInfo", , , "[PartNumber]=Forms![frm_PartDatabase].[PartNumber] AND [RevisionNumber]=Forms![frm_PartDatabase].[RevisionNumber] AND [CustomerNumber]=Forms![frm_PartDatabase].[CustomerNumber]"

  15. #15
    jobrien4 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    20
    Wait I think I figured it out.

    From the DoCmd.OpenForm, I added the Forms("frm_BevelInfo").AllowAdditions = False

    Then on the click button, I did:

    Forms("frm_BevelInfo").AllowAdditions = True
    DoCmd.RunCommand acCmdRecordsGoToNew
    Forms("frm_BevelInfo").AllowAdditions = False

    I'm not sure why that didn't work in the OnCurrent event, but whatever.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Show/Hide Form
    By sparlaman in forum Forms
    Replies: 5
    Last Post: 05-16-2011, 11:48 AM
  2. Hide textboxes only on new record.
    By SRSA in forum Programming
    Replies: 2
    Last Post: 02-28-2011, 04:31 PM
  3. hide checkbox in a form
    By hung_ko in forum Forms
    Replies: 11
    Last Post: 01-26-2011, 11:50 AM
  4. Hide Duplicates In Look Up Form
    By PonderingAccess in forum Queries
    Replies: 2
    Last Post: 09-30-2010, 12:23 PM
  5. Replies: 3
    Last Post: 09-15-2010, 01:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums