Custom properties from ODBC

Discussion in 'SolidWorks' started by mr.T, Jun 16, 2006.

  1. mr.T

    mr.T Guest

    Anybody tried pulling custom properties from ODBS or SQL Server using SW
    macro



    I think this is little bit over my head, but I'm willing to learn



    Looking for some tutorials, code examples or anything to get me started
     
    mr.T, Jun 16, 2006
    #1
  2. Hi

    We offer a SolidWorks add-on that can do that "out-of-the-box".
    Take a look at ToolWorks ERP-Link

    Download a trial from http://www.toolworks.info

    Jess
     
    Jess G. Frandsen, Jun 16, 2006
    #2
  3. mr.T

    mr.T Guest

    This is all pretty but it is way too complicated for what I need.



    I have existing DB +/-40K parts which can't be modified, all I'm looking
    for is macro that would take configuration name query it against the DB and
    fill the blanks inside custom properties
     
    mr.T, Jun 16, 2006
    #3
  4. mr.T

    Craig Guest

    Here is a code fragment which gets the description of a part from a SQL
    database (we use it to ensure the part desciptions match between
    Solidworks & the database)

    You need to have the Microsoft ActiveX Data Objects library selected
    for it to work.

    Look under tools > references in the VBA editor

    Private Sub getinfo
    Dim msg As String
    Dim style As String
    Dim SQLstr As String

    Dim rsta As New ADODB.Recordset
    Dim conn As New ADODB.Connection

    Set conn = New ADODB.Connection
    Set rsta = New ADODB.Recordset
    conn.ConnectionString = "Provider=SQLOLEDB.1;Password=******;" & _
    "Persist Security Info=false;User
    ID=UserID;" & _
    "Initial Catalog=ALLIANCE_ENG;Data
    Source=FINN;"
    On Error GoTo ErrHandler:
    conn.Open
    On Error GoTo 0

    rsta.Open "SELECT DESCTEXT FROM Partmaster WHERE PARTNUMBER='" &
    Trim(Partno) & "'", conn

    If rsta.EOF = False Then
    Description = CStr(rsta.Fields(0).value)

    Else
    msg = "Part Not Found in Alliance Partmaster Database "
    style = vbExclamation
    MsgBox msg, style, title
    End If
    rsta.Close
    Set rsta = Nothing
    conn.Close
    Set conn = Nothing

    ErrHandler:
    'clean up
    If conn.State = adStateOpen Then
    conn.Close
    End If

    Set conn = Nothing

    If Err <> 0 Then
    MsgBox Err.Source & "-->" & Err.Description, , "Error"
    End If
    End Sub
     
    Craig, Jun 18, 2006
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.