Results 1 to 3 of 3
  1. #1
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    101

    Change a lookup value according to combobox

    hello there,
    • I have a continuous subform "Child6" with fields: PN, ProductName and Price.
    • I also have a table called "Products" with the PN, ProductName, Price A and Price B.
    • on the parent form i have a combobox "SaleType"
    • There are also some buttons that populate the ProductName in the subform e.g. "BowlBtn" would fill up product "Bowl":



    Code:
    Private Sub BowlBtn_Click()
    Me.Child6.SetFocus
    DoCmd.GoToRecord , , acNewRec
    Me.Child6.Form.Product = "Bowl"
    End Sub
    So what I would like it to do is to have the price in the subform filled up depending on the SaleType selection,if it's "Local" it would have price A, if its "Web" it would have Price B, how could I do that?
    Thanks for your time in advance!

  2. #2
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    101
    i just figured it out with this code:
    Code:
    Private Sub BAtunBtn_Click()
    
    
        Dim LPrice As Variant
        Dim PPrice As Variant
        
        LPrice = DLookup("[PrecioL]", "[Precios]", "[Producto]='Bowl de Atún'")
        PPrice = DLookup("[PrecioP]", "[Precios]", "[Producto]='Bowl de Atún'")
        
        Me.Child6.SetFocus
        DoCmd.GoToRecord , , acNewRec
        Me.Child6.Form.Producto = "Bowl de Atún"
        
        If Me.SaleType = "Local" Then
            Me.Child6.Form.Precio = LPrice
        Else
            Me.Child6.Form.Precio = PPrice
        End If
    
    
    End Sub

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Why not do the lookup in the If construct?
    Then you only have to do one and not two all the time?
    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

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

Similar Threads

  1. Replies: 3
    Last Post: 07-05-2019, 02:41 PM
  2. Lookup and Combobox
    By majdoc in forum Access
    Replies: 5
    Last Post: 05-20-2019, 07:28 AM
  3. Replies: 7
    Last Post: 03-02-2016, 09:17 PM
  4. Combobox record lookup and .oldvalue compatibility issue.
    By MatthewGrace in forum Programming
    Replies: 3
    Last Post: 08-02-2014, 10:23 PM
  5. Replies: 1
    Last Post: 06-24-2013, 05:14 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