×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Searching Access Database from Solidworks VBA

Searching Access Database from Solidworks VBA

Searching Access Database from Solidworks VBA

(OP)
Good Day,
         Does anyone know the best way to pull information from an Access Database file. The values from the database are used as the input in a VBA macro. I can do it in Excel, but how do you set up a query in the VBA code to search for the record that matches specific criteria in the Access file.

Best Wishes,
Suzy

RE: Searching Access Database from Solidworks VBA

I've never used Access, but there's an API example on the SW website that talks about how to communicate with Excel.  It's the one that starts with "Automate Interaction with Microsoft Excel."

I hope that helps.

RE: Searching Access Database from Solidworks VBA

Its not quite that simple.

You have to know the DataBase table set up, and the individual record/field  data types.

 You can then set up queries to return recordsets.

The good news is that with VBA, you can often just import a module written in another Office app (Excel, Access) to your SWX app, add an early binding reference, and run the code from there.

RE: Searching Access Database from Solidworks VBA

step one make sure that you add a reference to the microsoft DAO 3.6 Object Library.
Dim db as object
Dim swRecord as Recordset
set db = opendatabase(string representing location of database)
set swRecord = db.openRecordset(string representing table or query name, dbOpenDynaset)
swrecord.MoveFirst
do until swRecord.EOF
      something = swRecord![Column Name]
      swRecord.MoveNext
Loop
swRecord.Close
db.Close
set swRecord = Nothing
Set db = Nothing

RE: Searching Access Database from Solidworks VBA

(OP)
Thank you very much Pake. That code worked on the first try. However I am trying to use SQL to do the searching. It has been rough going so far, but I thought I should give it my best before running back for help. I know it can be done. It is just a little tough.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources