Results 1 to 4 of 4
  1. #1
    gangel is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    194

    adding new record in different table than bound one!

    Hey pplz,
    Im learning access and coming along well, but just getting my brain from macros to vba which has been recommended me learning due to their versatility!

    Anyway I have
    DB = ZeroIt
    Tables = Stockadjustment, Stock
    Query= NegStock = List Stock with negative values

    SO I have a form bound to NegStock which just has the stock name and the Negative value.
    I have created a button which is currently NOT working (lol) that you press to zero the stock, however instead of just StockOnHand (SOH) = 0 I need to record my adjustments in the adjustment table!

    So I have made this vba module which runs but doesn't DO anything:

    Code:
    Private Sub Command55_Click()
      Dim db As DAO.Database
      Dim rs As DAO.Recordset
      Set db = CurrentDb
      Set rs = db.OpenRecordset("StockAdjustment")
      rs.AddNew
      rs![StaffID] = 207
      rs![ReasonID] = 2
      rs![SOHBeforeAdj] = Me.SOH.Value
      rs![SOHAfterAdj] = 0
      rs![StockID] = Me.StockID.Value
      rs![RealCost] = Me.RealCost.Value
      rs![DateCreated] = Date
      
      rs.Update
      rs.Close
      
    End Sub
    Can someone please tell me where im going wrong!

    Gangel

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The code looks good to me. You should set a breakpoint at Set db = CurrentDb and step debug to make sure your code is firing.

  3. #3
    gangel is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    194
    thanks ItsMe.
    I just went through it again and OMG found a stupid issue that was 100% my bad

    StockAdjust DATE is actually NOW as it has time in it.

    I have changed the date for now value in the list and it works. The values were all there but at the bottom of todays date (underneath hundreds of other adjustments from another program!)

    Thanks for the response!

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    OK, glad you were able to get it to work. IIRC the Date() function works with Date fields that store the Time, it just defaults to 12 midnight.

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

Similar Threads

  1. Adding New record to Table
    By Robert2150 in forum Forms
    Replies: 4
    Last Post: 03-24-2015, 10:42 AM
  2. Replies: 4
    Last Post: 08-14-2012, 07:14 AM
  3. Adding a record not found in another table.
    By Buakaw in forum Queries
    Replies: 1
    Last Post: 03-03-2011, 05:38 AM
  4. Re: Adding a new record to a joined table
    By Mcdodre in forum Access
    Replies: 4
    Last Post: 06-30-2010, 12:07 PM
  5. Replies: 10
    Last Post: 08-01-2009, 06:48 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