访问当前ID字段到Excel单元格

时间:2018-09-03 13:18:41

标签: excel ms-access access-vba

Project Management
Project Details

这是一个标准的项目管理数据库,当按下ID号时,它将转到“项目详细信息-pic2”。

此后,我插入了两个按钮(一个用于创建文件夹)和一个Excel按钮(用于打开特定模板)。

按钮一这样做:

Private Sub Command85_Click()


Const strParent = "F:\2. Prodaja\"
Dim projectID As String
Dim strFolder As String
Dim fso As Object
' Get ID from control
projectID = Me.ID
' Full path
strFolder = strParent & projectID
' Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Check whether folder exists
If fso.FolderExists(strFolder) = False Then
    ' If not, create it
    fso.CreateFolder strFolder
End If
' Open it
 Shell "explorer.exe " & strFolder, vbNormalFocus
 End Sub

和Excel按钮:

 Function OpenExcelFromAccess()
 Dim MyXL As Object

Set MyXL = CreateObject("Excel.Application")
With MyXL
    .Application.Visible = True
    .Workbooks.Open "F:\0. Main\01.Templates\ponuda.xltm"
    .Worksheets("Kupci").ListObjects("Employees__4").Refresh

   Dim EmpID As Integer
   EmpID = ID_Employees

.Worksheets("GlavnaTabela").Cells(3, 25).Value = EmpID

 End With
 End Function

这个想法是复制ID_Employee编号并将其粘贴到单元格Y3中,但它没有给我当前的ID_Employees数量,而是给我0。第一个按钮起作用并基于ID创建文件夹。我的问题是如何从Access Form中将ID_employees获取到Excel单元格Y3中?

我将功能更改为Sub并进行了以下更改:

Private Sub Command166_Click()

Dim EmpID As Integer
If IsNull(ID_Employees) Then EmpID = 0 Else EmpID = ID_Employees

Set MyXL = CreateObject("Excel.Application")
With MyXL
    .Application.Visible = True
    .Workbooks.Open "F:\0. Main\01.Templates\ponuda.xltm"
    .Worksheets("Kupci").ListObjects("Employees__4").Refresh
    .Worksheets("GlavnaTabela").Cells(3, 25).Value = EmpID

 End With
 End Sub

0 个答案:

没有答案