![]() Private Function LoadUserFile(ByVal AppHandle As Long, ByVal MyFileName As String) As Long MsgBox "Error # " & CStr(lngReturn), vbCritical, "Error"ĭblReturn = LoadMyFile("NotePad", vbNullString) LngReturn = LoadUserFile(Me.hwnd, "C:\Documents\My.mdb") (ByVal hwnd As Long, ByVal lpOperation As String, _īyVal lpFile As String, ByVal lpParameters As String, _īyVal lpDirectory As String, ByVal nShowCmd As Long) As Long Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _ The VB Shell function just performs a limited set of the options of the ShellExecute API. The following example uses both the ShellExecute API and the VB Shell function. ![]() You have more options, if you use the ShellExecute API. You need to use a space between the program name and the parameter hence, chr$(32). If you use the VB Shell function, you then must use the actual name of the program plus any parameters that may accompany the file. The operating system will use the program that is designated in the windows registry to open a file with that file's extension. In your case, you just want to use "open" for the operation. When you use the ShellExecute API you can just use "open", "print", or "explore" for the second parameter. Unless the programmer's intent was to optionally change the value of the variable. So, that function probably could have been more efficiently written by using ByVal. The function can then change the value of that variable, but it does not sound like it will. ![]() To get around the error and to use the function as is, just declare a variable and give it a value before sending it to the function. When your function uses ByRef, then you need to send a variable. If the function requires a variable, then you need to send a variable that you declared in your function. You receive the error because you are sending a value i.e. I can't open " & opFile, vbInformation vbInformation + vbOKOnly, "Error occured on file open" MsgBox "The file you are trying to open apparently has no program association available" & vbCrLf & "or it is a corrupted file. OpFile = Right(FN2Load, Len(FN2Load) - x)Ĭall Shell(retassoc(opFile, opPath) & " " & Chr(34) & FN2Load & Chr(34), vbNormalFocus) ' load the file in its' native application Success = FindExecutable(fn, fpath, sResult)įunction LoadUserFile(ByVal FN2Load As String) Private Const ERROR_BAD_FORMAT As Long = 11įunction retassoc(fn As String, fpath As String) As String Private Const ERROR_FILE_SUCCESS As Long = 32 'my constant Private Const ERROR_PATH_NOT_FOUND As Long = 3 Private Const ERROR_FILE_NOT_FOUND As Long = 2 Private Const ERROR_FILE_NO_ASSOCIATION As Long = 31 I am calling the function by Call LoadUserFile("D:\MB.mdb")Ĭode function i am using by Mike Bonnell Private Declare Function FindExecutable Lib "shell32" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal sResult As String) As Long Points error to opFile in following line Call Shell(retassoc(opFile, opPath) & " " & Chr(34) & FN2Load & Chr(34), vbNormalFocus)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |