Modules & VBA :: Call A Preimport Function Whenever Transfer-spreadsheet Is Called?
Oct 16, 2014
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
View Replies
ADVERTISEMENT
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.
View 5 Replies
View Related
Dec 30, 2014
I just want to run a series of DoCmd.TransferSpreadsheet commands to export several queries to one Excel Workbook with seperate sheet names for each query.
However my problem is I want this to be a new instance of Excel that the user will then SaveAs after it is complete. I don't want to save it to a specific path first because the Db is on a shared drive and My Documents will have a different path for each user based on their user name. (corporate environment)
There must be some way to just have it open a new workbook without saving isn't there??
View 3 Replies
View Related
Jan 26, 2015
From Here I want it to open the ".csv" that I chose (for some reason it doesn't now), Import to a table (I can do this part). Then export to the same location on the server with a different file name of my choosing and covert to .xlsx.
Dim fdlg As FileDialog: Set fdlg = Application.FileDialog(msoFileDialogFilePicker)
Do
With fdlg
.AllowMultiSelect = False
.Title = "Select File to Import"
.Filters.Clear
.Filters.Add "All Files", "*.*", 1
[Code] ....
View 3 Replies
View Related
Sep 18, 2014
DoCmd.TransferSpreadsheet Range parameter.
I want to import from an xls-File just the second page, titled "Harte". How do tell this the compiler?
Code is:
DoCmd.TransferSpreadsheet acLink, acSpreadsheetTypeExcel8, "Harte", file, True, "Harte"
View 1 Replies
View Related
Sep 17, 2013
I am extremely new to writing code, but was able to successfully write code that transfers the data in my form to and excel spreadsheet template and saves it with a different name. The code works perfect and without issue as long as Excel is not running. However if Excel is already open the template remains blank and a warning message appears saying that the form is locked for editing. Below is the code I used.
Private Sub ExcelClear_Click()
Dim xlApp As Excel.Application
Dim xlwrkBk As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = New Excel.Application
[Code] .....
View 2 Replies
View Related
Jun 1, 2015
I am trying to use transferspreadsheet to import access worksheet and then I want to append additional fields. I am able to import the excel sheet into access, but need appending the other fields.
Code:
Dim fd2 As FileDialog
Dim xlapp As New Excel.Application
Dim xlsht As Excel.Worksheet
Dim xlWrkBk As Excel.Workbook
Dim db As DAO.Database
Dim tb2 As TableDef
Dim fdx, fld As DAO.Field
[code]...
View 4 Replies
View Related
Sep 8, 2013
This module is giving me the "undefined function" error message when I try to run my query. I don't know why, but I have checked that there are no references with "missing" and there are not. I also added the word "Public" to the function becasue that was advised by another forum user. I thought it worked perfectly the first time I ran this query, but now it is not working and I do not recall making any changes. I have called the module basFunctions:
Option Compare Database
'************************************************* *********
'Declarations section of the module
'************************************************* *********
Option Explicit
'================================================= =========
' The DateAddW() function provides a workday substitute
' for DateAdd("w", number, date). This function performs
' error checking and ignores fractional Interval values.
'================================================= =========
Public Function DateAddW(ByVal TheDate, ByVal Interval)
Dim Weeks As Long, OddDays As Long, Temp As String
[code].....
View 3 Replies
View Related
Nov 18, 2013
I am struggling trying to execute a function inside a Form_current event to display some stats.
The Function is this:
Code:
Function FlightsByAircraft(Aircraft As Long) As Long
Dim rst As DAO.Recordset
Dim dbs As DAO.Database
Dim str As String
str = "SELECT * FROM tblFlights WHERE AircraftID = " & Aircraft
[Code] ....
The code for the Form_Current event is this:
Private Sub Form_Current()
txtStats1 = FlightsByAircraft(Me.AircraftID)
Very simple. Well, the problem is when I move to a new record, a error message comes up: "Run-time error '94' - Invalid use of Null". It is because the AircraftID is not populated at that time. I tried to insert in the function code something like that:
Code:
If IsNull(Aircraft) then
exit function
else
.... (the DAO.Recordset code)
but it doesn't work.
View 8 Replies
View Related
Nov 3, 2014
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
View 1 Replies
View Related
Aug 13, 2013
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
View 8 Replies
View Related
Jul 27, 2007
I have a database scheduled to run nightly. In this database I have a macro that runs a macro. I want one of the arguments to export "T_Update_Log" from the database to an excel file as part of it's nightly macro. When I use "Transfer Spreadsheet" in my macro, it creates a new worksheet in my excel file each night (for example: T_Update_Log1, T_Update_Log2, etc) Instead, I want it to overwrite existing one.
I have also tried "Export" command, but that throws a prompt asking if I want to overwrite the existing excel file. I cannot have any message prompts during my nightly task or else it will stop the whole process. Setting the Warnings to No does not stop this particular message prompt.
Thoughts? Thanks in advance!
View 2 Replies
View Related
Jul 19, 2005
This problem seems crazy to me.......
If I create a macro with a single entry consisting of Transferspreadsheet from a single Access table to Excel it exports perfectly. When I call Transferspreadsheet from VBA code it moves some of the data and puts them into seemingly random Excel spreadsheet columns why is this?
This issue first came about when we had to export a table with more than 65,000 records in and so I export using a table name "Sheet1" , "Sheet2" as needed but surely the table name that it comes from makes no odds?
Any help appreciated!
Regards,
Neil
View 2 Replies
View Related
Apr 21, 2006
I am using
DoCmd.TransferSpreadsheet acExport, , qName, wFilepath, True
to export a query to a spreadsheet. I am using this method as it seems to solve the problem of memo fields being truncated.
It seems however that using this method if the spreadsheet file already exists (and is of a differant structure) nothing happens and no error is thrown.
Is this correct? - Thanks Paul
View 3 Replies
View Related
Jan 18, 2006
Hi.
I developed a db on a local verison of Access 2003 (saved in Access 2000 format). It works great thanks to much help from this forum.
I recently moved the db to a server and tested how it worked when using Access 2000 on a citrix platform. This is important since the users of the db will be using this accursed platform. A few things (vba functions) broke but I deleted the affected code. However, one thing 'broke' that I can't eliminate.
When I click a button on one form I have a transfer spreadsheet command run to export the output of a query to a particular xls file/location. However, in the citrix environment I get an error message "Formats that enable export as html, xls, or rtf are missing from the windows registry".
I'm guessing this has something to do with the citrix server setup. Is there anything I can do on my end to avoid this problem or, as I fear, am I stuffed?
Cheers,
Craig
View 2 Replies
View Related
Jan 8, 2013
I am making my very first tentative steps to convert my most complex Access 2003 app to run under Access 2007. There are no obvious problems when simply opening my original MDB file in Access 2007 or running it after conversion to an ACCDB file. However, when I try to run the ACCDB file under the Access 2007 Runtime I get a "You can't carry out this action at the present time..." error. This is then followed by the "Execution of this application has stopped due to a runtime error..."
To be more specific, I only get that error when I deliberately hide the back end database and thus invoke code triggered via Autoexec to allow the user to browse for the missing database. This code works fine when running under normal Access 2007 so it appears to be a Runtime issue.
View 3 Replies
View Related
Aug 18, 2015
I'm working with Access 2010 and am trying to use the transferspreadsheet command to output data in a query to an Excel 2010 format file. Here is the line of code:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "q_calldetails_tmp", "c: emp estoutput.xlsx"
It works fine and produces the output file but when I try and open it with Excel I get an error saying the format is incorrect. If I change the extension to .xls it opens with no problem but I need it to be an Excel 2010 format with correct extension.
View 3 Replies
View Related
May 3, 2007
I did some searching and found this function posted by someone in response to the exact same problem I'm now encountering.
But how do I call this in my query?
Function StripZeros(pstr As String) As String
Dim n As Integer
n = 1
Do While Mid(pstr, n, 1) = "0"
n = n + 1
Loop
n = IIf(n > 1, n, 1)
StripZeros = Mid(pstr, n)
End Function
View 2 Replies
View Related
Dec 1, 2005
Hi all!
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??
Thanks :)
View 6 Replies
View Related
Oct 29, 2004
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
End Sub
eroness
View 1 Replies
View Related
Feb 23, 2007
http://www.access-programmers.co.uk/forums/showthread.php?t=123538
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.
View 4 Replies
View Related
Aug 10, 2007
Dear Access Query Expert
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.
Thank you so much.
View 1 Replies
View Related
Aug 8, 2006
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?
Thanks in advance for any help.
View 1 Replies
View Related
Apr 5, 2014
I have the following in Form and it works OK
Call RunForm("frmProviderLookup", "", "Edit", "", "", "Normal", "Normal")
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
View 1 Replies
View Related
Jan 16, 2007
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...
View 2 Replies
View Related
Jul 18, 2014
is it possible to call a function in a query with the input of a control element?
I have a form, and there is a list box in which I can choose the calculate method. In the query, a field should calculated with the choosen function.
Example:
Code : SELECT tblTest.price, tblTest.Date, forms![formtest]![lstChosenFunction](tblTest.price, 5) As Calc
...
The function has the same name as I can choose in the listbox. But, if I run the query a error appears.
Code : "Function forms![formtest]![lstChosenFunction] could not be found"
how I can call a function in SQL with the input of an listbox.
View 4 Replies
View Related