Results 1 to 4 of 4
  1. #1
    Mjz is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2017
    Posts
    7

    Edit Excel using Access VBA

    Hello, i would just like to know how to properly call a control box in Access VBA such that it updates a cell in an Excel file with that control box after i press a button. To make it more clear, here is what i have so far.



    Private Sub Command258_Click()


    Dim MySheetPath As String
    Dim Xl As Excel.Application
    Dim XlBook As Excel.Workbook
    Dim XlSheet As Excel.Worksheet


    MySheetPath = "P:\Fuse Selection\Database\tcc.xlsm"


    Set Xl = CreateObject("Excel.Application")
    Set XlBook = GetObject(MySheetPath)


    Xl.Visible = True
    XlBook.Windows(1).Visible = True


    Set XlSheet = XlBook.Worksheets(1)


    XlSheet.Range("C3") = Forms("FuseSelection").Text222 <--- Error here
    Set Xl = Nothing
    Set XlBook = Nothing
    Set XlSheet = Nothing


    End Sub

    I would just like C3 in my respective Excel file to be change to the value in the control box Text222 from my Form in Access.

    Thank you.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    start an instance of xl, then open the workbook, then set your cells....

    Code:
    Dim vFile
    Dim XL As Excel.Application
    
    vFile = "c:\folder\file.xls"
    Set XL = CreateObject("excel.application")
    With XL
        .Application.DisplayAlerts = False
        .Workbooks.Open vFile
        .sheets(1).select
        
        .Range("E4").Value = "new value"
        .ActiveWorkbook.Save
        .ActiveWorkbook.Close
        .Quit
    End With
    Set XL = Nothing

  3. #3
    Mjz is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2017
    Posts
    7
    Okay, im not sure i understand what you mean. If i changed the line
    XlSheet.Range("C3") = Forms("FuseSelection").Text22 to

    XlSheet.Range("C3") = "10"

    than everything works fine and the cell C3 in Excel updates to 10, i just do not know how to reference the "new value" if the new value is a textbox in my Access form.

    Thanks.

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    If the value is on the current form, use Me!Text22 (or Me.Text22). Add a debug stop marker on that line and see what the value is in the textbox, make sure that it is what you are expecting.

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

Similar Threads

  1. Replies: 11
    Last Post: 12-21-2023, 04:05 AM
  2. Access - edit forms.
    By honeybadger in forum Programming
    Replies: 3
    Last Post: 10-18-2016, 03:26 AM
  3. Replies: 1
    Last Post: 10-16-2016, 10:15 AM
  4. Access Opens Excel, Edit, SaveAs, then Close
    By jadown in forum Programming
    Replies: 6
    Last Post: 03-09-2015, 09:50 AM
  5. How to edit MS Access tables via web
    By russb in forum Access
    Replies: 1
    Last Post: 06-22-2013, 12:46 PM

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