Results 1 to 11 of 11
  1. #1
    sud2017 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2017
    Posts
    148

    Add Records to Query from a FORM

    I have created a query from multiple tables. I want to add records to the fields of this query from the textboxes in a form. I have added the fields in the FORM from the query fields and created a command button to add new record. when I click the command button, it says 'cant goto a specified record'. Code on the Click event of the command button looks alright. Query is updatable as I can add records manually into the query.

    Code in the command button:

    Private Sub Command33_Click()
    DoCmd.GoToRecord , , acNewRec
    Me!QuoteNo.SetFocus
    End Sub

    Forms allow addition property is set to yes.

    I'm doing a trial now so please ignore the command button name.

    Wondering if anything else is required to add records to the query. Thank you very much for any possible help.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Convention for data entry is 1 table for 1 form. Why do you have form bound to a multi-table query? Lookup tables can be included in form RecordSource but only to display related data, not to enter/edit data to the lookup tables.

    If you set QuoteNo textbox TabOrder property to 0, should not need the SetFocus code.
    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.

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    when I click the command button, it says 'cant goto a specified record'
    Is the "Allow Additions" property of your form set to "Yes"? It has to be if you want to be able to add new records.

  4. #4
    sud2017 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2017
    Posts
    148
    Thank you for your help. I got rid of query and used 1 table in subform. I am able to add records from the main form to the subform now. one thing which I still need help for is how to FILTER records of subform based on the combobox selection in my main form. combobox has PKand subform has corresponding FK for field called OppID. Anything with properties or codes to include? thank you for any possible help.


    Quote Originally Posted by June7 View Post
    Convention for data entry is 1 table for 1 form. Why do you have form bound to a multi-table query? Lookup tables can be included in form RecordSource but only to display related data, not to enter/edit data to the lookup tables.

    If you set QuoteNo textbox TabOrder property to 0, should not need the SetFocus code.

  5. #5
    sud2017 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2017
    Posts
    148
    further to my last comment, I have below code in afterupdate event of my combobox in main form, which is giving a 'runtime error 3071 - the expression is typed incorrectly or is to complex to be evaluated.....'

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    What do you mean by 'able to add records from the main form to the subform'?

    Why do you need to filter subform? Set the subform container Master/Child Links properties and the subform will only show records related to main form record. Is the main form BOUND?

    You did not post code.
    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.

  7. #7
    sud2017 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2017
    Posts
    148
    sorry the code:

    Private Sub Combo31_AfterUpdate()
    Forms!testquoteform3!Query1subform3.Form.Filter = "[OppID_FK] = '" & Me.Combo31 & "'"
    Forms!testquoteform3!Query1subform3.Form.FilterOn = True

    End Sub

    how to check if main form is bound? The fields on main form are added from a table.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    So the main form has a RecordSource and one of the fields is the PK?

    Apply filter to main form and the subform will synchronize if you set the Master/Child properties.

    The combobox must be UNBOUND.
    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.

  9. #9
    sud2017 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2017
    Posts
    148
    Mainform has a RecordSource which is say table 1. but the combobox from where I am trying to filter the subform has a RecordSource from another table (say table 2). The select values from Combobox are stored in table 1. From the same combobox I was trying to filter the subform records.

    However, I am fine with adding an UNBOUND combobox to filter records of subform, but because the values of combobox are not from table 1, the link master fields doesn't show the combobox fields because its from table 2. is there a way to achieve it?

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I am confused.

    Combobox has RowSource, not RecordSource.

    A control used to enter filter criteria must be UNBOUND otherwise you change the record.

    Most common use for a form and subform is to relate 'parent' and 'child' data. As example, main form bound to Orders table and subform bound to OrderDetails table.

    What is the relationship of your main and subform data sources?
    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.

  11. #11
    sud2017 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2017
    Posts
    148
    Thanks for your help June7. I have to fix a few things in my db to have a proper master/child relationships between form/subform. I got the way forward though. Thanks again.

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

Similar Threads

  1. Replies: 2
    Last Post: 07-07-2016, 07:01 PM
  2. Query form getting 1 of 0 records...
    By Xterra14s in forum Access
    Replies: 4
    Last Post: 06-13-2016, 01:44 PM
  3. Replies: 1
    Last Post: 07-26-2012, 10:51 AM
  4. Query by form does not show all records
    By 011billyw in forum Forms
    Replies: 20
    Last Post: 03-20-2012, 05:10 PM
  5. Replies: 10
    Last Post: 12-21-2011, 01:24 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