Results 1 to 8 of 8
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    VBA Help - Calculeted Value In A Text Box To Be Stored In A Table

    I am using the following and is working perfect
    Private Sub NEXPPRC_AfterUpdate()
    Me.[Purchase Description] = Me.NEXPPRC.Column(0)


    Me.[Purchase Price] = Me.NEXPPRC.Column(1)
    Me.[Purchase Units] = Me.NEXPPRC.Column(2)
    Me.[Purchase Sales Tax] = Me.NEXPPRC.Column(3)
    Me.[aasc] = Me.NEXPPRC.Column(4)
    Me.[agentc] = Me.NEXPPRC.Column(5)
    Me.[aasnetc] = Me.NEXPPRC.Column(6)
    Me.Requery
    Me.Refresh
    End Sub


    The above is for combo box, Now I want to use similar code to store calculated text in a field to the table "Purchases" but for the text box

    Name of the text box:
    Atcom
    calculation Value:
    AASTamt: ([aasc]*[Purchase Qty])

    I tried but this is not working on the text box Atcom


    Private Sub Atcom_AfterUpdate()
    Me.[Atcom] = Me.([aasc]*[Purchase Qty]).Column(0)
    Me.Requery
    Me.Refresh
    End Sub

    Please Help Me fix the code

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is the table "Purchases" part of your form's RecordSource?

  3. #3
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    Yes
    table "Purchases" is a part of form's RecordSource

  4. #4
    trevor40's Avatar
    trevor40 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    407
    debug it, set 2 new text boxes on your form to equal me.aasc and me.[Purchase Qty].Column(0) then calculate the result in another text box. you can then use this to see were the error is. an alternative way is to use vba variables and step debug through your code.

    ps this line is wrong
    Me.[Atcom] = Me.([aasc]*[Purchase Qty]).Column(0)
    it should read
    Me.[Atcom] = Me.[aasc]*Me.([Purchase Qty]).Column(0)

    1000 ways to skin a cat, allways looking for another one...
    Use MDB format for sample post. If your issue is fixed, mark the thread solved.
    Click on the star below if this has helped.

  5. #5
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    am totally confused can you please explain it in steps

  6. #6
    trevor40's Avatar
    trevor40 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    407
    Private Sub Atcom_AfterUpdate()
    'change this line
    Me.[Atcom] = Me.([aasc]*[Purchase Qty]).Column(0)
    'to this
    Me.[Atcom] = Me.[aasc]*Me.([Purchase Qty]).Column(0)
    Me.Requery
    Me.Refresh
    End Sub

    see if that works

    1000 ways to skin a cat, allways looking for another one...
    Use MDB format for sample post. If your issue is fixed, mark the thread solved.
    Click on the star below if this has helped.

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Why do you have this line: Me.[Atcom] = Me.[aasc]*Me.([Purchase Qty]).Column(0) in the After Update event of the textbox Atcom? The code will never run unless you type something in the textbox, and then it will change whatever you typed to the calculated value - you can type anything you like and it will be changed.

    Is [Purchase Qty] also a combo box?

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by aamer View Post
    Yes
    table "Purchases" is a part of form's RecordSource
    Assuming you have a properly joined Record Source then what Trevor40 has in post #4 should work.

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

Similar Threads

  1. Replies: 9
    Last Post: 02-16-2015, 05:54 PM
  2. Use VBA to call stored SQL from table
    By hcruz in forum Programming
    Replies: 2
    Last Post: 05-02-2011, 08:26 AM
  3. combo box selection stored in table
    By combine21 in forum Forms
    Replies: 1
    Last Post: 12-02-2010, 09:57 PM
  4. Number stored as text
    By Mclaren in forum Programming
    Replies: 1
    Last Post: 05-15-2010, 03:11 AM
  5. Dividing a number stored as text
    By Mclaren in forum Programming
    Replies: 1
    Last Post: 05-04-2010, 07:50 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