Results 1 to 6 of 6
  1. #1
    gillyr7 is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    3

    Use form to update multiple records based on dropdown

    I am new to Access, so I apologise if this is very easy. I have a table (shown below) where one field has duplicate values (male and female). I would like my form to select male or female in the drop down, and then enter in the amount in the text box. After that, I click the button and every value for my drop down selection is updated with the amount I typed in. Is this possible?



    Original Table:
    Click image for larger version. 

Name:	Table.PNG 
Views:	14 
Size:	5.3 KB 
ID:	33881

    Form:
    Click image for larger version. 

Name:	Form.PNG 
Views:	14 
Size:	2.5 KB 
ID:	33882

    End Result:
    Click image for larger version. 

Name:	TableEndResult.PNG 
Views:	14 
Size:	5.5 KB 
ID:	33883

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    when user picks the gender, filter the list:
    Code:
    cboGender_afterupdate()
      If IsNull(cboGender) Then
      Me.FilterOn = False
    Else
      Me.Filter = "[gender]='" & cboGender & "'"
      Me.FilterOn = True
    End If
    end sub
    then clicking the button will update those record using a query
    Code:
    sub btnUpd_click()
        docmd.openquery "quUpd1GenderAmts"
    end sub
    the query quUpd1GenderAmts, would look like
    update table set [amount] = forms!myForm!txtAmt where [gender] = forms!myForm!cboGender

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,127
    Hi & welcome to the forum

    Yes it is easy - you need to create an update query (or the SQL equivalent) that runs either from a button click or the after update event of the Gender or Amount controls
    Suggest you use a button click

    In the query add the fields Gender & Amount.
    In the update to row for Amount field, enter the control name Forms!MyFormName.txtAmount
    For the Gender field, enter Forms!MyFormName.cboGender in the criteria row

    SQL equivalent is (replace with your button name, table name, form & control names)

    Code:
    Private Sub Command1_Click()    
        CurrentDb.Execute "UPDATE MyTableName SET MyTableName.Amount = " & [Forms]![MyFormName].[txtAmount] & "" & _
            " WHERE (((MyTableName.Gender)='" & [Forms]![MyFormName].[cboGender] & "'));"
    
    End Sub
    EDIT - I typed this before seeing ranman's answer. Choose whichever you prefer
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  4. #4
    gillyr7 is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    3
    I tried to run this, but I keep getting the error: Microsoft Access can't find the field '|1' referred to in your expression. Do you know where that might stem from? Thanks.

    Update Query:
    Click image for larger version. 

Name:	Update Query.PNG 
Views:	11 
Size:	15.0 KB 
ID:	33888


    Button Error:
    Click image for larger version. 

Name:	Button Error.PNG 
Views:	11 
Size:	20.8 KB 
ID:	33889

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,127
    I had intended you would adapt my code to you own table, from and control names rather than repeat my own.
    The query as written should work from the button click on the form or as suggested use the SQL version I posted before.

    If you are still stuck, I can post a working example using that code.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  6. #6
    gillyr7 is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    3
    I got it to work. Thanks for your help.

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

Similar Threads

  1. Replies: 9
    Last Post: 10-23-2017, 06:32 PM
  2. Replies: 3
    Last Post: 06-24-2017, 07:37 AM
  3. Replies: 2
    Last Post: 07-07-2016, 07:01 PM
  4. Replies: 14
    Last Post: 06-22-2016, 04:08 PM
  5. Replies: 4
    Last Post: 08-25-2013, 07:43 AM

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