Results 1 to 8 of 8
  1. #1
    ManuelLavesa is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    113

    Selecting a record before opening a form

    Hello,
    I have a Form and a dialog box. The form consists of a Main Form and a Subform, Both have record sources from different queries and they are linked by a field named fkOrderID. The subform is a scrolling type. The main Form contains a field named InvoiceNumber.
    The dialog Box consist of an Unbound combobox that has as record source the Orders Table, which stores the value for the field InvoiceNumber. Also it has a Button with the following code:

    Private Sub EditSaleOrder_Click()
    If IsNull(CboInvoiceNumber) Then
    MsgBox ("Please Enter an Invoice Number from the List")
    Exit Sub
    End If
    DoCmd.OpenForm "SalesOrderEntryFormEditing", acNormal, , "[InvoiceNumber]=" & Me.[CboInvoiceNumber], acFormEdit
    DoCmd.Close acForm, Me.Name
    End Sub

    When you press the button it opens the form at the given Invoice value so that we can edit the record. This works fine as long as the original record has values in the form and the subform. However if for any reason the subform has no values then pressing the button opens a new record even though the combobox contains the Invoice Number that I want to edit and the Table Orders also contains the InvoiceNumber and parts of the Information from the Main Form. I am not sure what I am doing wrong. I would really appreciate it if you could help me. Thank you in advance for your time and efforts.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Just for grins, leave off the last argument (acFormEdit). I believe it will work as you want.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Each RecordSource property draws data from different queries and those queries are pulling from different tables?

    Main form should be bound to parent table (such as Orders) and subform bound to dependent table (such as OrderDetails). Linking should be on primary key and foreign key fields. You say linking is on 'a field named fkOrderID' - what are the primary and foreign key field names?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    ManuelLavesa is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    113
    Hello, Thank you to both of you. I tried removing the acFormEdit, and it made no difference. About the form is linked by OrderID from table Orders (Master) and fkOrderID from table OrderDetails (subform). Somehow I think I should make the table OrderDetails accept Null values or something. Is there a trick to do that? Thank you.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    That sounds like a conventional arrangement. If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    It reads like this Private Sub EditSaleOrder_Click() is on one form, and this CboInvoiceNumber (assuming "I have a dialog box" means it's a different form) is on another ( or the subform). If that's the case, If IsNull(CboInvoiceNumber) should raise an error. AFAIK, you cannot even refer to a main form control this way from a subform. You should get Data member not found, or unknown variable depending on how it's written.
    Last edited by Micron; 08-08-2017 at 09:52 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.

  7. #7
    ManuelLavesa is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    113
    Hello I have good news I did solve the problem. It had to do with the record source of the main form that some how contained some data from the OrderDetails Table and was interfering with the record source of the subform. Now everything works. Thank you for your help and time.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    That's great! Thanks for the update.

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

Similar Threads

  1. Replies: 5
    Last Post: 01-24-2015, 12:59 AM
  2. Replies: 1
    Last Post: 06-23-2014, 05:25 AM
  3. Selecting a record from a sub form
    By pfales in forum Programming
    Replies: 19
    Last Post: 06-10-2013, 04:32 AM
  4. Replies: 9
    Last Post: 09-16-2011, 03:52 PM
  5. Replies: 3
    Last Post: 05-02-2011, 07:34 AM

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