combining code

johnlatona123

Innovator
Local time
Today, 11:49
Joined
Sep 20, 2011
Messages
85
hi all,

i could use some help trying to combine this code together to occur as one on_load sub routine.

heres what we got:

Private Sub Form_Load()
Dim rs As adodb.Recordset
Do While Not Recordset.EOF
Dim sPath As String
sPath = "N:\DRAWINGS\" & [Drawing#] & "-01_" & [DwgRev] & ".dwg"
If FileOrDirExists(sPath) Then
[Verify] = True
Else
MsgBox sPath & " does not exist."
End If
Recordset.MoveNext
Loop

End Sub

_________________________________________-

Private Sub Form_Load2()
Dim rs As adodb.Recordset
Do While Not Recordset.EOF
Dim tPath As String
tPath = "N:\DRAWINGS\" & [Drawing#] & "-02_" & [DwgRev] & ".dwg"
If FileOrDirExists(tPath) Then
[verify2] = True
Else
MsgBox tPath & " does not exist."
End If
Recordset.MoveNext
Loop

End Sub

ive highlighted the sublte differences between the two subs to illustrate the difference in function.

so maybe im having a special moment here or something, but for whatever reason i cant get the second sub there to do anything at all, so i thought maybe if i combine the two together?

please help!
 
Are you indicating the first one runs fine, then the second one doesn't run?
add
debug.print "recordset eof is: " & Recordset.eof
before the Do While statement
Debut.Print " tPath string is: " & tPath
just after the tPath assignment
debug.print "File exist status: " & FileOrDirExists(tPath)
before the If statement and turn on your Immediate Window

I typically comment out my debug statements later in case trouble shooting is needed later. A comment won't really bother your execution time.
 
Where you trying to achieve ? ...

Code:
Private Sub Form_Load()
Dim rs As adodb.Recordset
Dim sPath As String, tPath As String
Do While Not Recordset.EOF

  sPath = "N:\DRAWINGS\" & [Drawing#] & "-01_" & [DwgRev] & ".dwg"

  If FileOrDirExists(sPath) Then
    [Verify] = True
  Else
    MsgBox sPath & " does not exist."
  End If

  tPath = "N:\DRAWINGS\" & [Drawing#] & "-02_" & [DwgRev] & ".dwg"

  If FileOrDirExists(tPath) Then
    [verify2] = True
  Else
    MsgBox tPath & " does not exist."
  End If

 Recordset.MoveNext
Loop

End Sub

I assume that these are controls on a form. You might do better to use a Command button to run it rather than just running it when the form loads.

This way the form will have a chance to load before launching into the code otherwise the form may just appear frozen as it opens. ...

Code:
Private Sub cmdTest_Click()
  doTest
End Sub

Private Sub doTest()
Dim rs As adodb.Recordset
Dim sPath As String, tPath As String
Do While Not Recordset.EOF

  DoEvents ' Allows the form to catch up with any changes

  sPath = "N:\DRAWINGS\" & Me.[Drawing#] & "-01_" & Me.[DwgRev] & ".dwg"

  me.Verify = FileOrDirExists(sPath)
  if not me.Verify then 
    MsgBox sPath & " does not exist."
  End If

  tPath = "N:\DRAWINGS\" & Me.[Drawing#] & "-02_" & Me.[DwgRev] & ".dwg"

  me.verify2 = FileOrDirExists(tPath)
  if not me.verify2 Then
    MsgBox tPath & " does not exist."
  End If

 Recordset.MoveNext
Loop

End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom