[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 619
  • Last Modified:

How to match list file using DIR and wildcard in VBA. Mine currently pulls the first match.

Here is my current code that will pull the first match;
....

strFirstMatch = Dir("\\sfile0\e\cnc\vm2\" & Forms!frmHurcoSetups.ProgNum & "*" & ".HD3") & ""
If strFirstMatch <> "" Then

MsgBox "Access moved the following program to the " & Me.cboMachine & "'s Unproven folder. " & Chr(10) & strFirstMatch & _
Chr(10) & "Be sure the Revisions on the Tool Sheet and the program match before finalizing the Tool Sheet."

    FSObj.MoveFile ("\\sfile0\e\cnc\vm2\" & strFirstMatch), _
         "\\mikem\g\" & Forms!frmSplash.cboMachine & "\unproven\" & strFirstMatch

Else

MsgBox "The application was unable to locate a program for this tool sheet. " & _
"You will need to manually move the program from the Server to the unproven folder. " & _
"Be sure the Tool Sheet # does not have the revision or hd3 in the name before closing the Tool Sheet back out."
...

Open in new window


Thanks for the input!
0
SeyerIT
Asked:
SeyerIT
  • 2
  • 2
1 Solution
 
Rey Obrero (Capricorn1)Commented:
try this


strFirstMatch = Dir("\\sfile0\e\cnc\vm2\" & Forms!frmHurcoSetups.ProgNum & "*" & ".HD3") & ""

If  strFirstMatch = "" Then

MsgBox "The application was unable to locate a program for this tool sheet. " & _
"You will need to manually move the program from the Server to the unproven folder. " & _
"Be sure the Tool Sheet # does not have the revision or hd3 in the name before closing the Tool Sheet back out."

else

While strFirstMatch <> ""  

MsgBox "Access moved the following program to the " & Me.cboMachine & "'s Unproven folder. " & Chr(10) & strFirstMatch & _
Chr(10) & "Be sure the Revisions on the Tool Sheet and the program match before finalizing the Tool Sheet."

    FSObj.MoveFile ("\\sfile0\e\cnc\vm2\" & strFirstMatch), _
         "\\mikem\g\" & Forms!frmSplash.cboMachine & "\unproven\" & strFirstMatch


strFirstMatch=Dir

Wend

End if

Open in new window

0
 
SeyerITAuthor Commented:
Well That is close I suppose.. It is moving all occurrences that it finds with that. Is it possible to move just the last occurence?
0
 
Rey Obrero (Capricorn1)Commented:
i thought you want to get all that match..
what do you mean by the last occurence?
0
 
mbizupCommented:
Try this:


....

Dim strLast as string
strFirstMatch = Dir("\\sfile0\e\cnc\vm2\" & Forms!frmHurcoSetups.ProgNum & "*" & ".HD3") & ""
If strFirstMatch <> "" Then

MsgBox "Access moved the following program to the " & Me.cboMachine & "'s Unproven folder. " & Chr(10) & strFirstMatch & _
Chr(10) & "Be sure the Revisions on the Tool Sheet and the program match before finalizing the Tool Sheet."

    FSObj.MoveFile ("\\sfile0\e\cnc\vm2\" & strFirstMatch), _
         "\\mikem\g\" & Forms!frmSplash.cboMachine & "\unproven\" & strFirstMatch

Else
    strLast = strFirstMatch
    strFirstMatch = dir()
    Do Until strFirstMatch  = ""
              strLast = strFirstMatch
              strFirstMatch  = Dir()
   loop
   if strLast = "" then

MsgBox "The application was unable to locate a program for this tool sheet. " & _
"You will need to manually move the program from the Server to the unproven folder. " & _
"Be sure the Tool Sheet # does not have the revision or hd3 in the name before closing the Tool Sheet back out."
Else
        FSObj.MoveFile ("\\sfile0\e\cnc\vm2\" & strLast), _
         "\\mikem\g\" & Forms!frmSplash.cboMachine & "\unproven\" & strLast
end if

end if

Open in new window

...
0
 
SeyerITAuthor Commented:
Excellent! Thanks a bunch!

Thanks as well for your input capricorn!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now