Results 1 to 10 of 10

Thread: [RESOLVED] Updating stocks and Comprehensive VBA tutorials

  1. #1

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Resolved [RESOLVED] Updating stocks and Comprehensive VBA tutorials

    Hi to all!

    I have a main form in ms access (OrderEntryForm) and a subform(OrderEntrySubform). These forms are similar to northwinds orders form.
    My question is how do i update the quantity on hand field in the OrderEntrySubform after I inputted the payment in the txtAmount in the OrderEntryForm. The OrderEntrySubform is bound to a query (qryOrderDetails) similar to northwind's order details extended..
    The code below illustrates when the cashier inputs payment in the txtAmount the and press enter, the change due is computed...

    Here is the scenario....

    Product Code: a-111
    Name: Jergens
    Stocks: 200
    Quantity Ordered: 10

    Product Code: a-112
    Name: Graham Crackers
    Stocks: 300
    Quantity Ordered: 15

    Product Code: a-113
    Name: Cream-O
    Stocks: 100
    Quantity Ordered: 5




    Total Due: 490
    (txtAmount) --> Payment: 500
    Change Due: 10.00

    When the txtAmount_LostFocus() is called, the change due is computed and the stocks for Items Jergens, Graham Crackers, and Cream-O will be updated into 190, 285, and 95 respectively...Hope you got my point...

    VB Code:
    1. ' Main form: OrderEntryForm textbox (txtAmount)
    2.  
    3.         Private Sub txtAmount_LostFocus()
    4.            'these four lines will compute for the change due
    5.            total = txtTotal.Value
    6.            amt_paid = txtAmount.Value
    7.            change = amt_paid - total
    8.            txtChange.Value = change
    9.        
    10.            'code for updating the quantity on hand
    11.            ???????????
    12.  
    13.         End Sub

    If you can provide me with comprehensive tutorials on VBA for ms access, it would be a great help also...

    Hoping for any response....


  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Updating stocks and Comprehensive VBA tutorials

    Quote Originally Posted by KGComputers
    If you can provide me with comprehensive tutorials on VBA for ms access, it would be a great help also...
    Here are some things that I hope you will find useful.

    http://mis.commerce.ubc.ca/courses/c...htm#whatfilter

    http://cisnet.baruch.cuny.edu/holowc...accessall.html

    http://www.functionx.com/access/

  3. #3

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: Updating stocks and Comprehensive VBA tutorials

    Hi Hack!!!

    Thanks for posting the links....I already have a copy of those links...Functionx.com is one of my references for all my projects...

    What I'm trying to emphasize is this....

    I have this code in visual basic 6.0 using ADO and Listview control, and the Item Table...This code will update the stocks of the products(Item table)...(new stock = current stocks - quantity ordered) in the Item table...For every product registered in the listview, the quantityonhand will be updated based from customer purchases.

    VB Code:
    1. For i = 1 To lvwSales.ListItems.Count
    2.                 item_name = CStr(Trim(lvwSales.ListItems(i).Text))
    3.                 q_order = Val(lvwSales.ListItems(i).SubItems(4))
    4.                
    5.                 rstItem.Open "Select * from Item", cnn, adOpenDynamic, adLockPessimistic
    6.                 Do While rstItem.EOF <> True
    7.                     If rstItem.Fields("Item_Code") = item_name Then
    8.                         cnn.BeginTrans
    9.                         curr_stocks = Val(rstItem.Fields("QuantityOnHand"))
    10.                         rstItem.Fields("QuantityOnHand") = curr_stocks - q_order
    11.                         cnn.CommitTrans
    12.                     End If
    13.                     rstItem.MoveNext
    14.                 Loop
    15.                 rstItem.Close
    16.                
    17.                 curr_stocks = 0
    18.                 q_order = 0
    19.                        
    20.             Next i

    My question is how can I convert this vb6.0 code into an MS Access VBA code? Is ADO in vb 6.0 very similar to MSAccess VBA? How can I update the stocks in the subform like what i did using vb 6.0 listview control? I only have little experience using VBA...

    This client of mine wants sales orders be manipulated directly through a database (ms access) w/o using front-end vb 6.0 applications..

    Hoping for a response......

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Updating stocks and Comprehensive VBA tutorials

    VBA is a subset of VB, so I'm guessing that much of your code would transfer with relative ease.

    I believe that Access does have a ListView component. If I incorrect in this, then I know it does have a multicolumn listbox (one of the very few things I find envious about. Why couldn't that have been included with VB as well?)

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Updating stocks and Comprehensive VBA tutorials

    The ListView control is not part of the default control in the Access Toolbox. You can add one as an additional control but if you distribute the database you will need to distribute the comctl2.ocx also and register it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Updating stocks and Comprehensive VBA tutorials

    Quote Originally Posted by RobDog888
    The ListView control is not part of the default control in the Access Toolbox. You can add one as an additional control but if you distribute the database you will need to distribute the comctl2.ocx also and register it.
    But, Access does have a multicolumn listbox control, right?

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Updating stocks and Comprehensive VBA tutorials

    Yes, basically its default toolbox is almost the same as vb6's default toolbox.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: Updating stocks and Comprehensive VBA tutorials

    Good day gurus.....

    thanks for the spark...Yes indeed, there is a listview control in the MS Access database.I will try that later on...

    My point is the products which the customer ordered is entered using a subform which is also bound to a query.The query is bound to a query (qryOrderDetail) and this query is bound to the Item table..The subform does not apply listview..What Im trying to emphasize is without using listview, just the plain subform in a datasheet view similar to Northwinds database Orders subform, how can I update the stocks of the products using VBA code? In listview we can use its listitems() and subitems() to access the elements right? In an ordinary subform in datasheet view, how can we access the elements like quantityordered and etc....hope you get my point....The code will be added in the txtAmount_LostFocus() which is my first post....

    Waiting for your responses......

  9. #9

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: Updating stocks and Comprehensive VBA tutorials

    Hi RobDog8888 and Hack...

    Is this the listview control your talking about( Microsoft Listview Control 6.0) ? I'm using access 2000.The active x component (comctl2.ocx), if I plan to distribute a database using listview, how will I do that? Say, my client has also MS Office 2000 in his PC...

    Yes, listbox in MS Access is also quite nice which should also be included in the VB later on...

    Hoping for any response on my previous post.....




  10. #10

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: Updating stocks and Comprehensive VBA tutorials

    I just solved this...


    I just substituted the connection with this

    VB Code:
    1. Dim conn As ADODB.Connection
    2. Set conn = CurrentProject.Connection
    3.  
    4. Then I used the traditional code of ADO to update the stocks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width