Cogivina2004
MIS
How would I code in excel marco in order to read the value of a form (Form!Ult!DY) in access?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Private Sub Button_Click()
Dim objExcel As New Excel.Application
Dim objWorkbook As Excel.Workbook
Dim sourcefilepath As String, YYYYQ As String
DoCmd.SetWarnings False
YYYYQ = [Forms]![Ult]![DY] & [Forms]![Ult]![DQ]
DoCmd.OpenQuery "Delete TableTemp", acNormal, acEdit
sourcefilepath = "C:\MyFolder\Loss.xls"
Set objWorkbook = objExcel.Application.Workbooks.Open(FileName:=sourcefilepath)
objWorkbook.worksheets(1).range("A1").formula = YYYQ
objExcel.Run ("GetData")
objWorkbook.Close
objExcel.Quit
Set objWorkbook = Nothing
Set objExcel = Nothing
DoCmd.Close acForm, "Ult", acSaveYes
End Sub