How to show changes in open Access Database Table in VB?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • George Yar
    New Member
    • Feb 2011
    • 2

    How to show changes in open Access Database Table in VB?

    Re: How to show changes in open Access 2003 Table in VB

    I have a form to add a new record to my Access Database table.

    This is a code:

    Code:
    Private Sub btnAdd_Click()
    
    
       Dim dbExpenses As DAO.Database
       Set dbExpenses = CurrentDb
       
    ................................
    'To Get the RecordID
    'Add new record
       Dim rstFDet As DAO.Recordset
       Set rstFDet = dbExpenses.OpenRecordset("Food   Details", dbOpenDynaset)
       
       rstFDet.AddNew
       rstFDet("Food Category ID").Value =  Forms!AddFoodDetRecord!lstFCat
       rstFDet("Food Category Name").Value = Forms!AddFoodDetRecord!lstCatName
       rstFDet("Shop Name").Value = Forms!AddFoodDetRecord!cmbShop
       rstFDet("Date").Value = Forms!AddFoodDetRecord!tbDate
       rstFDet("Type").Value = Forms!AddFoodDetRecord!cmbType
       rstFDet("Name").Value = Forms!AddFoodDetRecord!cmbName
       rstFDet("Quantity").Value = Forms!AddFoodDetRecord!tbQuant
       rstFDet("Coupons").Value = Forms!AddFoodDetRecord!tbCoupons
       rstFDet("Sale Savings").Value = Forms!AddFoodDetRecord![tbSavings]
       rstFDet("Amount").Value = Forms!AddFoodDetRecord!tbAmount
       rstFDet.Update
       
       rstFDet.Close
    .......................................................
       
    'Enable Undo action
       Me!btnUndoAdd.Enabled = True
    
    End Sub
    All works OK.
    The only problem I have: If the table "Food Details" is open in other window in Datasheet view, no changes are visible.
    Obviously, I should add some line to the code, but I don't know what it should be.

    How to refresh the table's datasheet view programmaticall y in VB?
    Last edited by Stewart Ross; Feb 6 '11, 10:22 PM. Reason: corrected code tags
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    You can't really update a table viewed in datasheet format, so instead I'd suggest that you design a form for displaying the table (or query) concerned in datasheet format. Once this is done you can easily add a line of code to the end of your update routine which will requery the form:

    Code:
    Forms("YourDataSheetFormName").Requery
    By the way, it is good practice not to have tables opened directly by users. Always use appropriate forms to front-end the tables.

    -Stewart

    Comment

    • George Yar
      New Member
      • Feb 2011
      • 2

      #3
      Stewart, thank you for replay.

      It works just fine.

      Comment

      Working...