Results 1 to 3 of 3
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371

    Excel Options From Access

    Hi All, does anyone know how to add a command button to Cells("1:1") to an Excel work sheet ? and program the command button with an input box to search text ?, i have done lots of these in Access but not tried to generate to Excel

    ie:

    [Dim mInput, mYear As LongDim ApXL, XLWb, XlWs1, xlWs2, xlWs3, xlWs4, xlWs5 As Object
    Dim wsAdd1, wsAdd2 As Worksheet
    Dim strPathName, mAsc, Cust, Src As String
    Dim rs, rs2, rs3, rs4, rs5 As DAO.Recordset
    Dim mStart, mEnd As Date


    mStart = "01/01/2018"
    mEnd = "31/12/2018"
    strPathName = "T:" & "DMT DELIVERIES" & ".xlsx"
    Cust = "MyCustomer"


    Src = "Acc"
    mYear = DatePart("yyyy", Me.txtUpdate)
    Set ApXL = CreateObject("Excel.Application")
    Set XLWb = ApXL.Workbooks.Add
    ApXL.Visible = True
    Set XlWs1 = XLWb.Worksheets("Sheet1")
    XlWs1.Name = mYear & "-" & "DELIVERIES"
    Set xlWs2 = XLWb.Worksheets("Sheet2")
    xlWs2.Name = "COLLECTIONS"
    ApXL.ActiveWorkbook.SaveAs (strPathName)
    Set rs = CurrentDb.OpenRecordset("SELECT tblAssign.DelTo, tblAssign.DeliveryDate, tblAssign.SONumber FROM tblAssign WHERE DeliveryDate Between #" & mStart & "# And #" & mEnd & "#" & " And Customer = '" & Cust & "'" & " And SOURCE = '" & Src & "' ORDER BY DeliveryDate Desc")
    Set rs2 = CurrentDb.OpenRecordset("SELECT tblCollections.DelTo, tblCollections.CollectedDate, tblCollections.SONumber FROM tblCollections WHERE Customer = '" & Cust & "'" & " And SOURCE = '" & Src & "' ORDER BY CollectedDate DESC")
    Set XLWb = ApXL.Workbooks.Open(strPathName)
    With XLWb
    .Worksheets(1).Cells(1, 1) = COMMAND BUTTON inputbox("Enter SL-Number ?","SEARCH SL-NUMBER")
    Worksheets(1).Cells(1, 3) = "DEALER"
    .Worksheets(1).Cells(1, 4) = "DELIVERY DATE"
    .Worksheets(1).Cells(1, 5) = "SL-NUMBER"
    .Worksheets(1).Cells(3, 3).CopyFromRecordset rs
    .Worksheets(1).Cells.EntireColumn.AutoFit
    .Worksheets(1).Cells.EntireColumn.HorizontalAlignm ent = xlLeft
    .Worksheets(1).Range("C3:C6").Borders(xlEdgeBottom ).LineStyle = xlContinuous
    .Worksheets(2).Cells(1).CopyFromRecordset rs2
    .Worksheets(2).Cells.EntireColumn.AutoFit
    .Worksheets(2).Cells.EntireColumn.HorizontalAlignm ent = xlLeft
    .Save
    End With]

    OR INSTEAD OF GENERATING A NEW XL SHEET EVERY MORNING, KEEP THE SAME ONE WITH A COMMAND BUTTON INPUT BOX AND UPDATE CELLS ("1:3") / ("1:4") and ("1:5")

    Many Thanks

    Dave

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    Can depend on the Excel version, but in 2016 on Ribbon > Developer > Insert to put a control on a sheet. You'll get a prompt to assign or create a macro. Create will open the vb editor. The related method would be to create what is called a userForm (not form) in Excel. To keep using the same sheet, you'll have to edit an existing one rather than create, or use one as a template to create new ones.

    As an observation the way you declare your variables on one line means that everything that's not explicitly typed (and I don't mean keyboard) is a variant.
    e.g. only Src is a string, the rest are variants and you're relying on Access to correctly figure it out when values are assigned.
    Dim strPathName As String, mAsc As String, Cust As String, Src As String
    not
    Dim strPathName, mAsc, Cust, Src As String
    unless you intended them to be variants.

    EDIT
    Forgot to request that for more than a few lines of code, please use code tags (# on forum toolbar) along with proper indentation to make your code easier to read. Also prevents forum from adding spaces at the 50 character mark, which only adds to confusion in code posts.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Hi Micron, much appreciated, will give those changes a go, i have done a lot in access VBA but not excel!!

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

Similar Threads

  1. Access 2GB Limit Size Options
    By ewalkerpcs in forum Access
    Replies: 8
    Last Post: 10-17-2016, 07:11 PM
  2. Export to Excel with Filter Options
    By dcoley in forum Import/Export Data
    Replies: 1
    Last Post: 02-05-2014, 12:44 PM
  3. I can't see the menu options in Ms Access 2010.
    By dave_joseph in forum Access
    Replies: 2
    Last Post: 10-27-2011, 03:11 AM
  4. Access Options
    By arunsule in forum Programming
    Replies: 2
    Last Post: 08-02-2011, 12:41 PM
  5. Access Options Button
    By 95DSM in forum Programming
    Replies: 1
    Last Post: 08-16-2010, 03:05 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