Results 1 to 7 of 7
  1. #1
    Kipandrews06 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    54

    GoTo new record on main form from a cmd button on subform

    I'm sure I'm probably an idiot and this is an easy fix, but I'm having trouble figuring out how to get my DoCmd.GoToRecord function to go to a new record.

    So I have a main form with two subforms.



    On subform 1, it is just a product list
    On subform 2, it is an item cart

    I had a hard time coding my item cart to update all the products and the amounts when submitted so I wasn't able to get the cmd button "Submit Order" to be on the main form, it had to be with the record source on the item cart or else I probably wouldn't be having this issue. So I have it where the submit order button is on the item cart (subform 2). The problem I am having is when I try to do the DoCmd.GoToRecord,,acNewRec it keeps saying I have a type mismatch error. I've tried referencing my main form which is called frmOrderDetails. I've tried the setfocus on it and it is still not working. Does anyone have any ideas on how I get the main form to go to a new record from a cmd button on subform 2?

    My main form is called frmOrderDetails
    My subform2 is called frmItemCartOrdersSubform

  2. #2
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Type mismatch means you're trying to put a value in a field or control that wants a different type. That can be text where only numbers/dates are allowed, or Null (no value) where it is not allowed to be Null. Text fields will accept numbers but will convert them to text if possible.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Kipandrews06 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    54
    Yeah I am stumped. Because I've tried about 15-20 different variations. I just tried this:
    Code:
     DoCmd.GoToRecord acDataForm, "frmOrderDetails", acNewRec
    and this gave me an error:2046 cmd or action isn't available right now.

  4. #4
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    So now a different error? Make sure you can go to a new record interactively (e.g. via ribbon or built in form record navigation controls). If not, you can't do it by code. Your form records could be read only, thus you can't go to new. Could also happen in code if you're already at a new record. Could also be that the form you want to do this on has lost the focus. Either a db copy or more code would help. One line of code isn't much to go on. Probably need the whole sub/function.
    Last edited by Micron; 03-07-2022 at 02:51 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Kipandrews06 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    54
    I was able to fix it by doing a SetFocus on the main form. I had tried it before I posted but I guess I did with with an incorrect syntax or something. Really not sure.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    To me, that would be very confusing (easliy done I know ), but put objects for the subform on the subfom and object for the main form on the main form?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Kipandrews06 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    54
    @Welshgasman LOL yeah I guess it is a little confusing. I've never done an order form with an item cart before so I've been learning on the fly. Basically I have a main form with two subforms. One of the subforms is a product list where they simply scroll through the products they need and can click on an add button which adds the product into the other subform which is an item cart. All the forms are linked together and are in sync but have different record sources. The main form is where they enter in all the address information, but when they are done, they click on a submit order button in the item cart subform which loops through all the products in the item cart and deducts the qty they order from inventory and then make the main form and both subforms go to a new record which is where I was having an issue in this post. Once I did the SetFocus to the main form, it fixed the problem and works perfectly now! This is the code that fixed it:

    Code:
         Forms!frmOrderDetails.SetFocus
                    DoCmd.GoToRecord , "frmOrderDetails", acNewRec
    I was using a bracket for the frmOrderDetails instead of "" and I took out the acDataForm

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

Similar Threads

  1. Replies: 4
    Last Post: 03-18-2019, 08:50 AM
  2. Replies: 3
    Last Post: 09-08-2017, 07:18 PM
  3. Replies: 2
    Last Post: 11-14-2014, 03:07 PM
  4. Replies: 6
    Last Post: 05-18-2013, 12:48 AM
  5. Replies: 13
    Last Post: 01-29-2012, 01:45 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