Results 1 to 2 of 2
  1. #1
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    Open Form To Corresponding Product and Create New Record

    I am trying to open my main form from another form. The form opened shows the ProductName and other stuff. My main form has a subform on it where products are entered. I would like to open my main form, create a new order, and display the Corresponding Products in my subform.



    Form opened is InventoryReceiving, Main form is OrderDetails and subform is OrderDetailsSubform where the ProductID is located.

    Here is my code now that opens my main form but not to a new record or displays the corresponding Product on the subform.

    On Error GoTo Err_Command51_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "OrderDetails" 'Opens Corresponding Order
    DoCmd.GoToRecord acDataForm, "OrderDetails", acNewRec


    stLinkCriteria = "[ProductName]=" & Me![ProductID] 'This wont work I'm sure.
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_Command51_Click:
    Exit Sub

    Err_Command51_Click:
    MsgBox Err.Description
    Resume Exit_Command51_Click

    ____________________________________
    DoCmd.OpenForm "OrderDetails", , , "[ProductID]=forms![OrderDetails].form![ProductID]" 'Trying this to see if it will work??? NOPE! It DOES NOT WORK EITHER
    DoCmd.GoToRecord acDataForm, "OrderDetails", acNewRec
    Attached Thumbnails Attached Thumbnails MainMenuProductsSubform.jpg   InventoryReceivingForm.jpg  
    Last edited by burrina; 12-20-2012 at 10:06 AM. Reason: Trying Adjusted Code

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Am I getting Close? No, errors out on this line of code; Forms!OrderDetails!OrderDetailsSubform.Form.Produc tID .SetFocus (On SetFocus) is the error!


    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "OrderDetails" 'Opens Corresponding Product and Creates a New Order

    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.GoToRecord acDataForm, "OrderDetails", acNewRec
    Forms!OrderDetails!OrderDetailsSubform.Form.Produc tID .SetFocus
    DoCmd.FindRecord Me.ProductID

    __________________________________________________ ___________Trying New Code,Almost there,could use some help.
    Private Sub Purchase_Click()
    On Error GoTo Err_Command51_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "OrderDetails" 'Opens Main Form OrderDetails.

    DoCmd.OpenForm stDocName, , , stLinkCriteria 'Link Criteria
    DoCmd.GoToRecord acDataForm, "OrderDetails", acNewRec 'Creates New Record
    Forms!OrderDetails!OrderDetailsSubform.Form.SetFoc us 'Sets Focus on Subform OrderDetailsSubform
    ProductID.SetFocus 'Sets Focus To Product Field
    With Me.[ProductID].Form.RecordsetClone 'Does Something?
    .AddNew 'Adds New Record
    !ProductID = Forms!InventoryControl!ProductName 'Unsure but Link by Product Name
    !ProductID = ProductID 'ProductID = ProductID
    'etc.
    .Update 'Updates the form with criteria.
    End With 'End Routine

    Exit_Command51_Click:
    Exit Sub

    Err_Command51_Click:
    MsgBox err.Description
    Resume Exit_Command51_Click
    End Sub
    Last edited by burrina; 12-21-2012 at 08:04 AM. Reason: Further Code Trials

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

Similar Threads

  1. Replies: 2
    Last Post: 10-08-2012, 12:39 PM
  2. Replies: 3
    Last Post: 08-26-2012, 10:04 PM
  3. create a button to open a form for data entry
    By dave john in forum Programming
    Replies: 3
    Last Post: 08-21-2012, 08:41 AM
  4. Replies: 1
    Last Post: 05-03-2012, 02:25 PM
  5. Replies: 5
    Last Post: 10-28-2011, 02:42 PM

Tags for this Thread

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