Results 1 to 5 of 5
  1. #1
    jzeig1 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2018
    Posts
    6

    DoCmd OpenForm to new record

    Hay all. I will try to make this as simple as possible, but I know you need as much info as well: ;-)

    I have a main form that has a comboBox(cmdMemberName) the has member first and last name orderBy last name, which is the first field in the dropdown.
    I have two buttons on the presently (will add 'delete' button later): one is cmdEditMember the other is cmdNewMember.


    I was working with at tutorial that uses the following code:

    DoCmd.RunCommand acCmdRecordsGoToNew Me.mbr_LastName = " "
    Call cmdEditMember_Click

    That would work fine if I was in datasheet view or the my current focus was on a record within that data sheet, but I'm using a comboBox to populate a subform. I'm not trying to change any of the values in the subform, just the member list within the cmbBox.
    Using the code above, the idea here is that the current form would create a new record when cmdNewMember is clicked; fill in [LastName] with a blank value; then cmdEditMember would extract the openArg value to goto to the new record.
    This won't work for me cause I'm using a comboBox, and it doesn't allow edit in that manner - not to mention that the 'notOnList' event would trigger; additionally, if there was a way to do it using the comboBox properties, it would probably be lengthy. That-being-said:

    DoCmd.Close acForm, "frmMbrDonation"
    DoCmd.OpenForm (frmMemberInfo,acNormal,,,acFormAdd,acWindowNormal ,,)

    I was trying to open it using the cmdNewMember button to open the form and set it to a new record. I've tried the above code but I get an error (Compile error: Expected expression)

    Thanks

  2. #2
    jzeig1 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2018
    Posts
    6
    Nevermind. I sat down and walked thru it.

    Here's what I came up with.

    DoCmd.Close acForm, "frmCurrent"
    DoCmd.OpenForm "frmMemberInfo"
    DoCmd.RunCommand acCmdRecordsGoToNew

    That seems to work.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Welcome to the site and thanks for following up with your solution. Your OpenForm was on the right track with acFormAdd. The form name needed to be in quotes and I don't think you needed the parentheses. The trailing commas may also have been a problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    jzeig1 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2018
    Posts
    6
    Quote Originally Posted by pbaldy View Post
    Welcome to the site and thanks for following up with your solution. Your OpenForm was on the right track with acFormAdd. The form name needed to be in quotes and I don't think you needed the parentheses. The trailing commas may also have been a problem.
    Thank you. If it ain't broke, don't fix; therefore, I'll leave it the way it is for now. I'll try to use the 'OpenForm' syntax with all those parameters later - it would be good to understand the function all the parts.

    "I'll be back!"

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I have the same philosophy. That said, your method could get slow if the underlying table gets large, since all records would be returned. Just a heads up.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 10-27-2017, 04:10 AM
  2. Replies: 11
    Last Post: 08-22-2017, 05:50 PM
  3. Replies: 19
    Last Post: 01-03-2017, 02:23 PM
  4. DoCmd.OpenForm with 2 Where Conditions
    By CharissaBelle in forum Programming
    Replies: 3
    Last Post: 10-19-2016, 09:32 AM
  5. What actually happens at docmd.openform
    By Beorn in forum Programming
    Replies: 4
    Last Post: 01-05-2011, 02:19 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