Hi Guys!
I’m struggling to link my Custom Properties with a table of MS Access
Linking Means Pasting the details from Access to Custom Properties.
For Eg: If I have a model No: 500 is open in solidworks , I need the codes that will search that Part Number in that table and update the corresponding Properties in Custom Properties.
Please support.
(Please find an attachment of the Pick and Database)
Similar Code for Excel, but unable to connect with Access DB
.............................................................................................................................................................
Dim swApp As SldWorks.SldWorks
Dim excApp As Excel.Application
Dim swModel As SldWorks.ModelDoc2
Dim swCustPrpMgr As SldWorks.CustomPropertyManager
Sub main()
Set swApp = Application.SldWorks
Set swApp = Application.SldWorks
Set excApp = GetObject(, "Excel.Application")
Set swModel = swApp.ActiveDoc
Set swCustPrpMgr = swModel.Extension.CustomPropertyManager("")
Dim excRange As range
Dim excSheet As Excel.Worksheet
Set excSheet = excApp.ActiveSheet
Set excRange = excSheet.range(excApp.Cells(1, 1), excApp.Cells(1000, 1))
Dim searchRes As range
Dim name As String
Dim index As Integer
Dim title As String
title = swModel.GetTitle()
index = InStr(title, ".")
name = Left(title, IIf(index = 0, Len(title), index - 1))
Set searchRes = excRange.Cells.Find(name)
If Not searchRes Is Nothing Then
LinkPrpToCell searchRes.row, 1, "EPMPartNumber"
LinkPrpToCell searchRes.row, 2, "EPMPartName"
LinkPrpToCell searchRes.row, 3, "EPMDescription"
LinkPrpToCell searchRes.row, 4, "EPMMaterialReference"
LinkPrpToCell searchRes.row, 5, "Density"
LinkPrpToCell searchRes.row, 6, "EPMMaterial"
Dim density As Double
density = CDbl(excApp.Cells(searchRes.row, 5).value * 1000000)
swModel.Extension.SetUserPreferenceDouble swUserPreferenceDoubleValue_e.swMaterialPropertyDensity, swUserPreferenceOption_e.swDetailingNoOptionSpecified, density
MsgBox "Properties Updated"
Else
MsgBox "Failed"
End If
End Sub