
Originally Posted by
help_me_with_access
Chronik,
to be honest with you, I assumed that you knew what you were doing with the SolidEdge stuff. I'm assuming you're calling up a library to work with them?
in every visual basic project you have to reference the windows libraries or other libraries you are going to use in order to get access to the elements within those libraries, for use in vb projects. Did you reference external libs in excel? if you did, you have to do the same thing in every office program. you have to tell the environment what libraries you need access to, otherwise it won't know.
is that the issue here I wonder?
Hi,
Yes i do know what i'm doing with the Solid Edge stuff. As I said, it works flawlessly in Excel/VBA. In both Excel and Access i've include library "Solid Edge File properties".
Here is the working excel code :
Code:
Sub GetFileProps()
Sheets("Sheet1").Range("A2:M20000").Value = ""
Dim strFile As String
Dim strPath As String
Dim FilePath As String
Dim colFiles As New Collection
Dim i As Integer
strPath = "C:\TEST\"
strFile = Dir(strPath)
Dim objPropSets As PropertySets
Dim objProps As Properties
Dim objProp As Property
Dim objPropIDs As PropertyIDs
Set objPropSets = CreateObject("SolidEdge.FileProperties")
Dim x As Integer
x = 2
While strFile <> ""
If Right(strFile, 3) = "psm" Or Right(strFile, 3) = "par" Then
colFiles.Add strFile
End If
strFile = Dir
Wend
If colFiles.Count > 0 Then
For i = 1 To colFiles.Count
FilePath = strPath & colFiles(i)
Call objPropSets.Open(FilePath)
Sheets("Sheet1").Range("A" & x).Value = colFiles(i)
Set objProps = objPropSets.Item("SummaryInformation")
Sheets("Sheet1").Range("B" & x).Value = objProps.Item("Title")
Sheets("Sheet1").Range("C" & x).Value = objProps.Item("Subject")
Sheets("Sheet1").Range("H" & x).Value = objProps.Item("Keywords")
Sheets("Sheet1").Range("L" & x).Value = objProps.Item("Author")
Sheets("Sheet1").Range("M" & x).Value = objProps.Item("Last Author")
Set objProps = objPropSets.Item("DocumentSummaryInformation")
Sheets("Sheet1").Range("G" & x).Value = objProps.Item("Category")
Set objProps = objPropSets.Item("MechanicalModeling")
Sheets("Sheet1").Range("D" & x).Value = objProps.Item("Material")
Set objProps = objPropSets.Item("Custom")
On Error GoTo Handler
Sheets("Sheet1").Range("E" & x).Value = objProps.Item("largeur")
Sheets("Sheet1").Range("F" & x).Value = objProps.Item("longueur")
On Error GoTo 0
Set objProps = objPropSets.Item("ProjectInformation")
Sheets("Sheet1").Range("I" & x).Value = objProps.Item("Document Number")
Sheets("Sheet1").Range("K" & x).Value = objProps.Item("Revision")
Sheets("Sheet1").Range("J" & x).Value = objProps.Item("Project Name")
Call objPropSets.Close
x = x + 1
Next i
End If
Sheets("Sheet1").Cells.Columns.AutoFit
Sheets("Sheet1").Range("A1").Select
Exit Sub
Handler:
If Err.Description = "Subscript out of range" And objProps.Name = "Custom" Then
temp = Err.Description
temp2 = objProps.Name
Resume Next
End If
End Sub
And here is the non working Access Code:
Code:
Option Compare Database
Public Sub UpdateTable()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("Table1")
Dim strFile As String
Dim strPath As String
Dim FilePath As String
Dim colFiles As New Collection
Dim i As Integer
strPath = "C:\TEST\"
strFile = Dir(strPath)
Dim objPropSets As PropertySets
Dim objProps As Properties
Dim objProp As Property
Dim objPropIDs As PropertyIDs
Set objPropSets = CreateObject("SolidEdge.FileProperties")
Dim x As Integer
x = 2
While strFile <> ""
If Right(strFile, 3) = "psm" Or Right(strFile, 3) = "par" Then
colFiles.Add strFile
End If
strFile = Dir
Wend
If colFiles.Count > 0 Then
For i = 1 To colFiles.Count
FilePath = strPath & colFiles(i)
Call objPropSets.Open(FilePath)
rs.AddNew
rs![File Name] = colFiles(i)
Set objProps = objPropSets.Item("SummaryInformation")
rs![Title] = objProps.Item("Title")
rs![Subject] = objProps.Item("Subject")
rs![Keywords] = objProps.Item("Keywords")
rs![Author] = objProps.Item("Author")
rs![Last Author] = objProps.Item("Last Author")
Set objProps = objPropSets.Item("DocumentSummaryInformation")
rs![Category] = objProps.Item("Category")
Set objProps = objPropSets.Item("MechanicalModeling")
rs![Material] = objProps.Item("Material")
Set objProps = objPropSets.Item("Custom")
On Error GoTo Handler
rs![Largeur] = objProps.Item("largeur")
rs![Longueur] = objProps.Item("longeur")
On Error GoTo 0
Set objProps = objPropSets.Item("ProjectInformation")
rs![Document Number] = objProps.Item("Document Number")
rs![Revision] = objProps.Item("Revision")
rs![Project Name] = objProps.Item("Project Name")
Call objPropSets.Close
rs.Update
x = x + 1
Next i
End If
Exit Sub
Handler:
If Err.Description = "Subscript out of range" Then 'And objProps.Name = "Custom" Then
Resume Next
End If
End Sub
When troubleshooting the code going line by line, should I see a new line being added and the file name entered when the code goes through :
Code:
rs.AddNew
rs![File Name] = colFiles(i)
Or does it appears only once it reaches
?
Thanks a lot for your help on this!