Ask Experts Questions for FREE Help!
  Advanced
Register  |  Log in  
   Ask    
 Answer  
  Help  

Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
Free Answers in 3 Easy Steps

Register Now
3 Steps

At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.

Home > Computers & Technology > Programming > Compiled Languages > Visual Basic   »   VBA & Excel Data Application

 
Question Tools Search this Question Display Modes
Question
 
 
#1  
Old May 2, 2007, 08:38 AM
hollertrek
New Member
hollertrek is offline
 
Join Date: May 2007
Posts: 1
hollertrek See this member's comment history on his/her Profile page.
VBA & Excel Data Application

I've done VBA applications and stand alone VB6 but that was a long time ago and not much with databases. I want to make a CAD software work with Excel by automating the process of taking a drawing template, saving it to a directory, and placing the next successive number back in Excel to create a list. The list would determine the next number to be used. So, I think it's a matter of query a worksheet/cell to have a starting place and build from there. Below is an example of code that already works with Access, but it also contains code from the (Autodesk Inventor) CAD VBA. I think it is routine for someone with experience. May we should dial with the data exchange only and I'll work out the other. Perhaps someone has done something like this before. Thanks.

Jon Holler





Option Explicit

Private Sub getNextPN_bak()
Dim oFileLocations As FileLocations
Dim rs As ADODB.Recordset
Dim CN As ADODB.Connection
Dim sql As String
Dim CP As String
Dim len1 As Integer
Dim c As Integer

Dim JobNo As Long
Dim BN As Integer
Dim BN1 As String
Dim BN2 As String
Dim PN As String ' Part No
Dim CH As String
Dim cs As Integer

' Open database connection
Set CN = New ADODB.Connection
CN.Provider = "Microsoft.Jet.OLEDB.4.0"
CN.Open "\\deepblue\EngineeringBOM\data\EngineeringBOM_dat a.mdb"

Set oFileLocations = ThisApplication.FileLocations

' CP = "C:\Projects\36550-36599\99999 Workspace" ' Test Data
CP = oFileLocations.Workspace
Debug.Print CP

' JobNo = Int(Mid(CP, 25, 5))
' Needs more intelligence... We do not always want to start at the 25th position.
' Instead, we need to write code to find the last "\" position and add one for the
' first variable of the Mid statement.

len1 = Len(CP) ' Length of workspace string
Debug.Print len1

For c = len1 To 1 Step -1 ' Evaluate string characters backwards
CH = Mid(CP, c, 1) ' Character
Debug.Print CH
If CH = "\" Then
cs = c + 1 ' determine starting character after '\'
Debug.Print CH & "!"
GoTo proceed1
End If
Next c

proceed1:
JobNo = Int(Mid(CP, cs, 5))
Debug.Print JobNo

sql = "SELECT tblBubbleNumbers.NextBubbleNumber FROM tblBubbleNumbers WHERE (((tblBubbleNumbers.JobNo) =" & JobNo & "));"
Debug.Print sql

' Open Recordset
Set rs = New ADODB.Recordset

rs.Open Source:=sql, _
ActiveConnection:=CN, _
CursorType:=adOpenStatic, _
LockType:=adLockOptimistic, _
Options:=adCmdText

rs.MoveFirst

BN = rs!NextBubbleNumber
Debug.Print BN

txtNextBubbleNumber.Value = Str(BN)

rs!NextBubbleNumber = BN + 1
rs.Update

' Close recordset
rs.Close
Set rs = Nothing

' Create Part Number
BN1 = Str(BN)
BN1 = Right(BN1, (Len(BN1) - 1)) ' Remove first character, for some reason the string conversion adds a space at the beginning

Debug.Print BN1
Debug.Print Len(BN1)
If Len(BN1) = 1 Then
BN2 = "000" & BN1
End If
If Len(BN1) = 2 Then
BN2 = "00" & BN1
End If
If Len(BN1) = 3 Then
BN2 = "0" & BN1
End If
If Len(BN1) = 4 Then
BN2 = BN1
End If
Debug.Print BN2

PN = Mid(Str(JobNo), 2) & "-" & BN2
Debug.Print PN

' Append New Part Number to Database

sql = "SELECT * FROM tblPartsListing WHERE PartNo = '" & PN & "'"
Debug.Print sql

Set rs = New ADODB.Recordset

rs.Open Source:=sql, _
ActiveConnection:=CN, _
CursorType:=adOpenDynamic, _
LockType:=adLockOptimistic, _
Options:=adCmdText

' rs.MoveLast

If (rs.EOF Or rs.BOF) Then
rs.AddNew
rs!PartNo = UCase(PN)

rs.Update
rs.Close
Else
MsgBox "A part with the number " & PN & " already exists in the database: ", vbInformation + vbOKOnly, "Error"
End If

' Close Database Connection
CN.Close
Set CN = Nothing

' Get Workgroup path
Dim CPX As String
Dim len2 As Long

Dim JobPath As String
Dim chx As String
Dim chx2 As Integer
Dim csx As Integer

CPX = oFileLocations.FileLocationsFile
Debug.Print CPX

len2 = Len(CPX) ' Length of FileLocationsFile
Debug.Print len2

For c = len2 To 1 Step -1 ' Evaluate string characters backwards
chx = Mid(CPX, c, 1) ' Character
Debug.Print CH
If chx = "\" Then
csx = c + 1 ' determine starting character after '\'
chx2 = chx2 + 1

If chx = "\" And chx2 >= 2 Then
Debug.Print chx & "!"
GoTo proceed2
End If
End If
Next c

proceed2:
JobPath = Left(CPX, (csx - 1)) & "Parts\"
Debug.Print JobPath

' Save Part to disk
' Dim oPartDoc As Inventor.Document - Duplicate Issue!
Set oPartDoc = ThisApplication.ActiveDocument
If oPartDoc.FullFileName = "" Then
Call oPartDoc.SaveAs(JobPath & PN & ".ipt", False)

End If

End Sub

Reply With Quote
 
     



Question Tools Search this Question
Search this Question:

Advanced Search
Display Modes

 
Similar Sponsors

Similar Questions
Question Asker Topic Answers Last Post
FNU & W-7 application -ITIN bijur Taxes 1 Feb 13, 2007 08:45 AM
VBA and Excel for office97 bkpsusmitaa Visual Basic 1 Jan 29, 2007 08:37 AM
Visual Fox Pro 9.0 data to Office documents (Word/Excel/Access) mgriba Access 0 Jan 24, 2007 01:03 PM
When do I mow, after weed & feed application? Faith Lawn & Garden 2 Aug 17, 2005 09:52 AM
Excel & Word compatibility jamiesb Spreadsheets 1 Jul 1, 2003 11:22 AM




Copyright ©2003 - 2007, Ask Me Help Desk.
All times are GMT -8. The time now is 03:12 PM.

Content Relevant URLs by vBSEO 3.0.0 RC6 © 2006, Crawlability, Inc.