Modules & VBA :: Static Shell Function Call Works But Dynamic Call Fails
Sep 4, 2013
I'm having to recode some old MS Access DBs so they will run in the following environments:
Office 2000 on WinXP
Office 2003 on WinXP
Office 2010 on WinXP
Office 2000 on Win7
Office 2003 on Win7
Office 2010 on Win7
When I wrote my code for Office 2000 on WinXP things were simple because directory paths were the same across all computers and I could hard code pathing when using a shell command to launch other files.
My new approach is to make a function call to the Windows registry to determine the default executable and path for opening a file based upon its extension (see apicFindExecutable in basWindows API module).
I'm able to use code to create a shell call and debug print it to the immediate window. If I put my cursor in the immediate window at the end of the shell call and hit [enter] the external file will open as desired. If I try to open the external file directly through code, I get a file not found error.
To recreate the error take the following steps:
(1) browse to files that are accessible from your computer
(2) click the PREPARE DATA AND OPEN MAIL MERGE DOCUMENTS command button
Shell function call is made by the fnOpenFile function located in the basOpenFile module. There has to be a trick here that I'm missing.
I'm looking to use the shell function to dynamically call different pdfs that are in a directory. However I'm getting run time error 5 "Invalid procedure or call argument".
Here is the code (very basic I know)..
Private Sub Liste_Documentation_DblClick(Cancel As Integer) Dim PathName As String PathName = Me.Liste_Documentation.Column(2) ' Debug.Print PathName Shell PathName End Sub
A typical filepath name is as follows..
S:VenteVendeursMarcCRMDOCSDiligences KYC - LABFT - V 2013 04 23.pdf
I have a form with a button to print preview a report. This report needs one input parameter before executing. The computer this will run on is a touch screen and does not have a keyboard. Windows 7 has a "on screen keyboard" program. I want this to run first so that my user can input the parameter.
I have the following which throws an "Invalid procedure Call or Argument"
Sub CallTeclado() Dim RetVal RetVal = Shell("c:windowssystem32osk.exe", vbNormalNoFocus) End Sub
I'm developing an application where I want to call the keyboard up on the screen when a user enters a field. This is my setup:
Windows 8.1 32 Bit, Access Runtime 2010. Exact lines of code are:
Dim RetVal RetVal = Shell("C:Program FilesCommon Filesmicrosoft sharedinkTabTip.exe")
These lines of code work perfectly fine on my development PC which is running Windows 7 64 bit, Access/Office 32 bit.
I know the path to the exe is good. I can navigate and double click it and it works great. but the shell command is resulting in the invalid procedure.
I need a search function that will not just open files based on their names but also drill into the documents and search based on what's in it. The only way I can see now is to use the Window's search function (the one at the start button). Is it possible to call that function into access?how do I re-create the search style of the windows search bar for a specific folder? Something like streamreader
I know its not possible. But Just wanted to confirm. Not at all possible?
Code:
Function PreImport(BookToImport As Workbook) For Each cell In BookToImport.Sheets(1).Rows(1).Cells cell.Value = Trim(cell.Value) Next cell BookToImport.Sheets(1).UsedRange.Rows(1).Replace ".", "_" End Function
When running a query in Access 2013 or 2010 we get an ODBC call failed. However when we run just the form, which the query connects to, it works just fine.
I have a query that returns some fields with "#Error" ...
The reason is that I call a function in the query, and the function chokes if there are no matches in my query criteria and therefore no argument is sent to the function.
I tried putting this in the function: var = Iif(IsNull(var) = True, 0, var) -but I still get "#Error" when there are no matching records.
I presume this is because not even Null is given to the function as an arg. Should I make the arg optional or how can I solve this??
I have linked an excel workbook as different tables in Access. The workbook contains a Microsoft Query. I have now found out how I can open and edit the workbook from access, how can I Update/refresh the MSQuery before I close it?
Here is what I have: Private Sub cmdTest1_Click() Dim MyXL As Object Set MyXL = CreateObject("Excel.Application") Set MyXLSheet = GetObject("c: est.xls") MyXL.Application.Visible = True MyXLSheet.Parent.Windows(1).Visible = True MyXL.Application.Cells(1, 1).Value = Now() MyXLSheet.Close SaveChanges:=True MyXL.Application.Quit Set MyXL = Nothing
Following on from that thread, I would really like to tidy up other areas of my front end. I am using the idea that Roy suggested and it works very well.
At the moment, I have a form, that has buttons on it that people click when they want to generate specific sheets from excel using data from access using VBA on the form. These work fine, however, now that the database is going live and all features need to be added, I think it would be nice to have one small form, with a list box.
I have converted a copy of the code on the form and placed in a module by declaring then functions instead of private subs.
At this stage, I tried doing it with macros running the code by using a series of runcode. I then created a table that has the macro name stored in it along with a decriptive bit of text detailing the excel chart that gets produced to make it easy for the user.
The list box populates itself correctly, but the problem I am having is I do not know how to make the 'go' button look at the list box, pull the hidden macro/function name from the list, then go and run the macro/function.
I have tried looking about, but have not found anyhthing.
I have created a query which has a function call as the criteria for one of the numerical fields. The function returns a string expression such as .....
1) 132 OR 142 OR 156 2) 132 OR 142 3) 132
..... into the criteria section of the numerical field.
Unfortunately, the query doesn't work if the criteria is generated by the function call. However, if I hardcode the criteria (don't send a function call but directly write 132 OR 142 OR 156) the query works.
I am puzzled and I am not sure how to solve this problem.
Is it possible to call a function from a field on a form, ie, in the control source put = FunctionName(abc)? Then I want to concantenate it to another variable so it would look like:
=FunctionName(abc) & TextVariable
I tried this and got the ?Name on the form, like it couldn't find the field name, which is really a function I'm calling.
Is this possible and if so, what am I doing wrong?
I want to build a combo box with several different RunForm variations as follows:
RunForm("frmProviderLookup", "", "Edit", "", "", "Normal", "Normal") RunForm("frmCustomerLookup", "", "Edit", "", "", "Normal", "Normal") RunForm("frmVendorLookup", "", "Edit", "", "", "Normal", "Normal") etc, there are many of these
When I select one the variations from the combo box the RunForm statement is stored in strAction varaible..How do I code the Call strAction line? (I want only one call statement).In other words how to call a Function from a variable...The start of my module Function works OK and looks like this:
Public Function RunForm(FormName As String, _ Optional WhereCondition As String = "", _ Optional xMode As String = "", _ Optional filterName As String = "", _ Optional Args As String = "", _ Optional WindowMode As String = "", _ Optional View As String = "")
' Parameters (all optional except parameter 1) ' 1 - Form Name ' 2 - Where condition ' 3 - Mode [Add, Edit, View(Read Only), ""(PropertySettings), DS(Datasheet Edit)] ' 4 - Filter Name ' 5 - Opening Arguments ' 6 - Window Mode ' 7 - Form View
With the script in the form that is part of MS-Access. I wonder how do I access/call the written function that are in the DLL file I made. I appreciate your help on this one...
I am trying to use a textbox value to call vba code and can not get it to work.
I keep getting an error on the call str1 line.
Code:
Sub formscript() Dim str1 As String str1 = [Forms]![fscripts2]![t3] 'MsgBox str1 If str1 = "" Then str1 = "err1" Exit Sub Else Call str1 ' this is where it call the script based on value in textbox End If End Sub
I am facing a problem with ODBC call failed error latly.The problem doesnt occur on my development PC but only on other PC's.I'm a beginer in Access, vba and I cant find a solution to make it work on every machines.
Code:
Dim qSQL As String DATA = "#" & DatePart("m", DATA) & "/" & DatePart("d", DATA) & "/" & DatePart("yyyy", DATA) & "#" qSQL = "SELECT Sum([IL]*[TO])" & _ "FROM PUBLIC_S INNER JOIN PUBLIC_SD ON PUBLIC_S.U = PUBLIC_SD.U " & _ "WHERE (((PUBLIC_SD.DAT)=" & DAT & ") AND ((PUBLIC_SD.ANA)='" & ANA & "') AND ((PUBLIC_SD.IA)='" & ia & "') AND ((PUBLIC_SD.AN_C)='PIMSS')); Set Db = CurrentDb() Set rs1 = Db.OpenRecordset(qSQL)
I have this segment of code that adds data to fields FName and FPath in the table Files. It works fine but the syntax is a nightmare with all the double quotes and symbols.
I have another field in the table Files called CompletedBy that shows who updated the table (they type their name into a textbox Text1 before clicking a command button to run the code). I would like to add this data to the table during the execution of strSQL. All the records added to the table Files will have that value in the CompletedBy field (say, Bob Jones).I tried the below changes but the code doesnt work.
I have 3 event procedure with 3 buttons to make them run.I would like to create another button that can run all procedures togehter. if I copy one of the procedures how do I tell it to run the other 2.
I spent all day trying to figure out why sometimes I can call an excel function from access and the value will appear on my form, but for some functions (F.inv, binom.inv), it errors out as "object not supported". I browsed all the available libraries in tools/reference but found nothing that seemed to solve this issue.
I am starting to explore VBA and Modules. I recently found a relativly simple way to add an Audit Log to a database without adding two tables for each table as outlined by Allen Browne.
I used a set of code from fontstuff.com and it works great, except when using a sub form. I belive that it is most likely because the use of the Tag property looks at the subform as a control but it holds no value. I am thinking the VBA needs to be altered or the BeforeUpdate command need to specify what form to look in.
The Before Update code is
Code:
Public Sub Form_BeforeUpdate(Cancel As Integer)
Code: If Me.NewRecord Then Call AuditChanges("SubForm_ID", "NEW") Else Call AuditChanges("SubForm_ID", "EDIT") End If End Sub
AuditChanges is the Module Event name and CustomerID is the unique identifer for a Subform.
On the Windows 7 Developer desktop, the Windows Theme is set to Windows 7.On the Citrix server (for users) the Windows Theme appears to be Windows 95. It is low graphics.The boxes are square instead of rounded. The selected Form Tabs just barely highlight with a thin line while on Windows 7, the selected Tab completely changes color. A basic Message box in Windows 95 looks square and flat. The title bar is very low graphics as one would expect when graphics were not great. Is there a VBA call that can display the OS Theme that affects MS Access? URL...
I was wondering if you can call a textboxes onExit event from another form? On my form a user enters a search criteria into a text box and when they exit the textbox the results are displayed in a listbox. This form is a subform on my main form. I want to be able to call this onExit method from the main form. Is that possible? When I put in txtSearchBox_Exit, I got an error saying Sub or Function not defined.