I am looking to write a VB Script which:
1) opens a browse file window
2) allows the user to select a file
3) writes the FILENAME that the user chooses to a a UDF in Item Maintenance.
Has anyone done this? I'm sure it must be possible!
I am looking to write a VB Script which:
1) opens a browse file window
2) allows the user to select a file
3) writes the FILENAME that the user chooses to a a UDF in Item Maintenance.
Has anyone done this? I'm sure it must be possible!
For item 2, there is the File System Object
http://msdn.microsoft.com/en-us/library/aa265304%28v=vs.60%29.aspx
Set fso = CreateObject("Scripting.FileSystemObject")
fileName = fso.GetFileName(fileName)
Set fso = Nothing
Here is the docs on item 1:
http://manual.pvxplus.com/directives/get_file_box.htm
So maybe something like:
oScript.Execute("InitialDir$ = ""S:\SERVER\PATH""")
oScript.Execute("GET_FILE_BOX READ FileName$,InitialDir$,""" & message & """")
looks like you can even define a file extension filter if you want.
[EDIT] This might be a little cleaner:
initialDir = "S:\SERVER\PATH"
oScript.Execute("GET_FILE_BOX READ FileName$,""" & initialDir & """,""" & message & """")
I been trying to do a similar thing. I have tried the script above but keep getting the following error:
OLE Error Number: -2147467259
Description
Language: VB Script
Script line: 32
Script Column: 0
MS Script Link Error Information
User... ERP100TEST Date... 7/16/2013 Time... 12:00:13
OLE Error Number... -2147467259 Description........ Language........... VBScript
Script Line........ 32 Script Column...... 0
1 : '
2 : ' Sage 100 ERP system variables
3 : '
4 : MAS_SCR_CMP = "NKC"
5 : MAS_SCR_USR = "bjc"
6 : MAS_SCR_MOD = "A/P"
7 : MAS_SCR_DTE = "20130716"
8 : MAS_SCR_HWD = "E:\APPS\sage\Sage 100 Advanced ERP\MAS90\home"
9 : MAS_SCR_LWD = "E:\APPS\sage\Sage 100 Advanced ERP\MAS90\soa"
10 : MAS_SCR_LIB = "E:\APPS\sage\Sage 100 Advanced ERP\MAS90\AP\AP_VENDOR.M4L"
11 : MAS_SCR_PNL = "PMAIN"
12 : MAS_SCR_OBJ = "BT_LINK_1"
13 : MAS_SCR_MSG = ""
14 : MAS_SCR_PFM = ""
15 : MAS_SCR_CS = 1
16 : MAS_SCR_DBG = 0
17 : MAS_SCR_ERR = 0
18 : '
19 : ' form variables passed in by Customizer
20 : '
21 : AP_Vendor_bus_UDF_DRAWING = ""
22 : '
23 : ' language : VBScript
24 : ' file name : ..\cm\script\001.txt
25 : ' script begin
26 : '
27 : Dim objShell
28 : Dim strFileName
29 : Dim strFilePath
30 : Dim objFile
31 : Set objShell = CreateObject("Shell.Application")
32 : Set objFile = objShell.BrowseForFolder(0,"Choose a file:",&H4000,"S:\Part Control Docs\Current Parts")
33 : strFileName = objFile.Title
34 : strFilePath = objFile.self.Path
35 : MsgBox "Just the file name: " & strFileName & vbcrlf & "The full path: " & strFilePath
36 : Set objFileName = Nothing
37 : Set objFilePath = Nothing
38 : Set objShell = Nothing
39 : retVal= oBusObj.SetValue("UDF_DRAWING$", strFileName)
40 :
41 : '
42 : ' script end
43 : '
BroseForFolder is really designed for just selecting folders, not files, which is why I suggested using the MAS 90 file dialogs above.
A brief google of the error comes up with others who have dealt with it already. www.tek-tips.com/viewthread.cfm
*Community Hub is the new name for Sage City