Hello Erin
i have some code to show you. This first part goes on your button in the on
click:
Private Sub cmdFolderFind_Click()
On Error GoTo Err_cmdFolderFind_Click
If IsNull(Me.Workorder) Then
Call fsFoldersearch(Me.cbProductTypeID, Left(Me.SerialNumber, 5),
Left(Me.SerialNumber, 5))
Else
Call fsFoldersearch(Me.cbProductTypeID, Left(Me.SerialNumber, 5),
Me.Workorder)
End If
Exit_cmdFolderFind_Click:
Exit Sub
Err_cmdFolderFind_Click:
MsgBox Err.DESCRIPTION
Resume Exit_cmdFolderFind_Click
End Sub
The second part is hefty and goes in a module:
Public Function fsFoldersearch(strProdType As String, strProductSerial As
String, strWorkOrderFolder As String)
Const strPathF As String = "P:\WO\"
Const strPathM As String = "\1 Completed\"
Const strPathDiv As String = "\"
Dim strFolder As String
'finding by workorder at begining of folder name in p drive workorder
product type folder
strFolder = Dir(strPathF & strProdType & strPathDiv & strWorkOrderFolder
& "*", vbDirectory)
If strFolder <> "" Then
MsgBox "The Product has not been completed.", vbOKOnly, "Not
Completed"
Shell Chr(34) & "EXPLORER.EXE" & Chr(34) & " " & Chr(34) & strPathF
& strProdType & strPathDiv & strFolder & Chr(34), vbNormalFocus
Else
'finding by workorder at begining of folder name in p drive
workorder product type completed folder
strFolder = Dir(strPathF & strProdType & strPathM &
strWorkOrderFolder & "*", vbDirectory)
If strFolder <> "" Then
Shell Chr(34) & "EXPLORER.EXE" & Chr(34) & " " & Chr(34) &
strPathF & strProdType & strPathM & strFolder & Chr(34), vbNormalFocus
Else
'finding by first five characters of serial number at begining
of folder name in p drive workorder product type folder
strFolder = Dir(strPathF & strProdType & strPathDiv &
strProductSerial & "*", vbDirectory)
If strFolder <> "" Then
MsgBox "The Product has not been completed.", vbOKOnly, "Not
Completed"
Shell Chr(34) & "EXPLORER.EXE" & Chr(34) & " " & Chr(34) &
strPathF & strProdType & strPathDiv & strFolder & Chr(34), vbNormalFocus
Else
'finding by first five characters of serial number at
begining of folder name in p drive workorder product type completed folder
strFolder = Dir(strPathF & strProdType & strPathM &
strProductSerial & "*", vbDirectory)
If strFolder <> "" Then
Shell Chr(34) & "EXPLORER.EXE" & Chr(34) & " " & Chr(34)
& strPathF & strProdType & strPathM & strFolder & Chr(34), vbNormalFocus
Else
'finding by Workorder anywhere in the folder name in p
drive work order product type folder
strFolder = Dir(strPathF & strProdType & strPathDiv &
"*" & strWorkOrderFolder & "*", vbDirectory)
If strFolder <> "" Then
MsgBox "The Product has not been completed.",
vbOKOnly, "Not Completed"
Shell Chr(34) & "EXPLORER.EXE" & Chr(34) & " " &
Chr(34) & strPathF & strProdType & strPathDiv & strFolder & Chr(34),
vbNormalFocus
Else
'finding by Workorder anywhere in the folder name in
p drive work order product type completed folder
strFolder = Dir(strPathF & strProdType & strPathM &
"*" & strWorkOrderFolder & "*", vbDirectory)
If strFolder <> "" Then
Shell Chr(34) & "EXPLORER.EXE" & Chr(34) & " " &
Chr(34) & strPathF & strProdType & strPathM & strFolder & Chr(34),
vbNormalFocus
Else
'finding by first five characters of serial
number anywhere in the folder name in p drive work order product type folder
strFolder = Dir(strPathF & strProdType &
strPathDiv & "*" & strProductSerial & "*", vbDirectory)
If strFolder <> "" Then
MsgBox "The Product has not been
completed.", vbOKOnly, "Not Completed"
Shell Chr(34) & "EXPLORER.EXE" & Chr(34) & "
" & Chr(34) & strPathF & strProdType & strPathDiv & strFolder & Chr(34),
vbNormalFocus
Else
'finding by first five characters of serial
number anywhere in the folder name in p drive work order product type
completed folder
strFolder = Dir(strPathF & strProdType &
strPathM & "*" & strProductSerial & "*", vbDirectory)
If strFolder <> "" Then
Shell Chr(34) & "EXPLORER.EXE" & Chr(34)
& " " & Chr(34) & strPathF & strProdType & strPathM & strFolder & Chr(34),
vbNormalFocus
Else
MsgBox "Folder does not exist",
vbOKOnly, "No Folder"
End If
End If
End If
End If
End If
End If
End If
End If
End Function
now that maybe over kill for you, but i had a few conditions to watch out
for. thing is it still doesnt work if someone doesnt follow the convention
when i set this up.
now here is the main part of the hefty code that you should look at
implementing your way:
Public Function fsFoldersearch(strProdType As String, strProductSerial As
String, strWorkOrderFolder As String)
Const strPathF As String = "P:\WO\"
Const strPathM As String = "\1 Completed\"
Const strPathDiv As String = "\"
Dim strFolder As String
'finding by workorder at begining of folder name in p drive workorder
product type folder
strFolder = Dir(strPathF & strProdType & strPathDiv & strWorkOrderFolder
& "*", vbDirectory)
If strFolder <> "" Then
MsgBox "The Product has not been completed.", vbOKOnly, "Not
Completed"
Shell Chr(34) & "EXPLORER.EXE" & Chr(34) & " " & Chr(34) & strPathF
& strProdType & strPathDiv & strFolder & Chr(34), vbNormalFocus
End If
End Function
notice that i have a "top" folder that i start in. as long as that is true
forever i dont have to worry about the variables at the top not working.
you will also notice i have 2 different kinds of products, completed and not
completed. this was something that made it that there were 2 places a product
could be. one other thing is the product type caused another set of
subfolders. so i could have 4 places to look depending on the product and the
completion. the completion was a function of production, had they finished
and shipped the product? the product type was either compressor or dispenser.
you situation might be different, you might need to just find the product
with in a "top" folder.
in my situation each natural gas compressor that we build is given a serial
number. in the folder that starts with the serial number there is all sorts
of information that anyone might need to see at anytime. this is why i built
this function in to the app that i created. on the main form they would be
"looking" at the database record and the button would grab the serial number
and use it to go find the folder for the product. a work order number is the
serial number of the compressor, hence the WO.
i think that you might need to think about how your products are stored, in
my case a work order folder was where the information about the product is
stored. if you are storing the information about the type of product, ie
wedges, then you may need to use the product number in the name of the folder
so that you have something unique to "find" with the code. this is probably
the biggest step in making this work. if there is nothing unique the code
will find the first one, open the folder and then stop. so if i had a folder
called "wood wedges" and "plastic wedges", and you gave the code "wedges" to
look for it would find the first folder, "plastic wedges" and open it, and
then stop.
i dont know what else to say... if you have any questions let me know here...
ttyl