"Check If File Is Open" Quandry.

Jun 16, 2005

Dim objExcel As Excel.Application
Set objExcel = New Excel.Application
Dim strFileName As String
strFileName = objExcel.Application.GetOpenFileName("Select CSV file, *.csv", , "CSV file")

If "FILE IS ALREADY OPEN" Then
MsgBox "File is currently open. Please close and re-run this program.", vbInformation, "Program Error"
GoTo end_:
Else
Set objworkbook = objExcel.Workbooks.Open(strFileName, , False)
objExcel.Columns("A:B").Insert Shift:=xlToRight
objExcel.Range("A5").FormulaR1C1 = "Account No"
objExcel.Range("B5").FormulaR1C1 = "Invoice No"
objExcel.Range("A6:A" & Range("C65536").End(xlUp).Row).FormulaR1C1 = Range("D1").Value
objExcel.Range("B6:B" & Range("C65536").End(xlUp).Row).FormulaR1C1 = Range("F1").Value
objExcel.Rows("1:4").Delete Shift:=xlUp

objExcel.Application.ActiveWorkbook.Close True
MsgBox "CSV file formatted.", vbInformation
End If

end_:
Set objExcel = Nothing
Set objworkbook = Nothing

Hi there,

I use the above code to open any CSV file, format it as required, then close/save it.

What I need to do is to find out if the file I have selected is already open and, if so, not to proceed with the code (see If "FILE NOT OPEN" line above).

I have tried several statements but am having no luck.

Thanks in advance,
Paul.

View Replies


ADVERTISEMENT

Kindly Check What Is Wrong In Checking An Excel File Open Or Not

Sep 17, 2004

halloo everybody
Here is my code to check an excel sheet wether it is open or not.
It is working good in the following situations.

1.if the excel file is not yet opened. then it is opening and bringing a value from some cell of the sheet1.
2.If the file is already opened and not yet closed. it is not opening again it is understanding that the file is already openrd and bringing the cell value.
3.It is working when it is closed by the user and again clicked the button to open. It is opening and bringing the value.
4.NOW the problem starts.
IT IS NOT WORKING , If I click the button again to open. It is opening another copy of the same file. I did't understand why is it working perfectly? before I close the file and not working if I close the File.

please kindly check my code and respond to me .
here is my code but it is not working when the file is already opened.


Private sub Cmd_Click()

Dim XL As New Excel.Application
Dim wbk As New Excel.Workbook
Dim ws As New Excel.Worksheet


WorkBookName = "Book2.xls"
If Not WorkbookOpen(WorkBookName) Then
chk = 1
Set wbk = XL.Workbooks.Open("C:Dokumente und EinstellungenKiran KarnatiDesktopEXCELBook2.xls")
Else
Set wbk = Workbooks(WorkBookName)
End If

Set ws = wbk.Worksheets("Sheet1")
If chk = 0 Then
With ws
Label48.Caption = .Cells(1, 2).Value
.Cells(1, 3).Select
End With
Else
With ws
Text49.Value = .Cells(1, 2).Value
End With
End If
XL.Visible = True

Set SA = Nothing
Set XL = Nothing
Set wbk = Nothing
End Sub
_________________________________________________


Function WorkbookOpen(WorkBookName As String) As Boolean
'Returns TRUE if the workbook is open
WorkbookOpen = False
On Error GoTo WorkBookNotOpen
If Len(Excel.Workbooks(WorkBookName).Name) > 0 Then
WorkbookOpen = True
Exit Function
End If

WorkBookNotOpen:
End Function

Thank you.
Kiran.

View 1 Replies View Related

General :: Batch File To Check (version) Of A File?

Aug 28, 2012

I use a batch file to distribute the front end of a database application. Currently, everytime the user clicks the shortcut on her desktop, the batch file executes and copies the front end from a network location to user's local machine. The FE is updated like every couple of days. The users run the database more frequently.

I would like to modify the batch file so that it checks some attribute of the FE file to decide whether it needs to be updated. I can't rely on file size, since the FE includes temporary tables. I essentially need something like the "tag" property of form controls, only for files. It would be ideal if it was me who sets this property, like "version number". Except it has read without opening the file itself.

View 14 Replies View Related

Bit Of A Quandry

Apr 26, 2005

Been awhile since I have been in the forums, but I was hoping to receive some enlightenment on a problem. I have a system that requires some simple data filtering/cleaning before it goes to processing. I have created 3 queries (the ones starting with ~) and need to have these fire in thier numbered order on the open event of the param form. Problem is that the original developer has his module load at that point so....

Should I alter the module to handle this, and if so....how???

Should I run it after the module and just refresh the form?

Note, that when this exceutes, all warning need to be set to OFF since this is automated overnight, and executed by macros.

Please let me know any thoughts you may have, all are appreciated.

View 1 Replies View Related

Combo Box Quandry

Jan 23, 2006

ok, so I felt like being slightly poetic.. :D

On to the problem. I have a form that's fairly complex and drives a report our sales and management departments use to determine a lot of business decisions. The form has a couple of date fileds and 10 combo boxes. Each combo box get's its list from a query of various product/accounting tables so that all unique posibilities for each catagory to select from are listed. So far everything works wonderfully, if slow due to the number of queries and form options to check when the report is run.

My problem starts when one of our managers wanted to suddenly get results for all SKU numbers that start with a certain string. Basically he wants to do a wildcard criteria in a combo box, which of course doesn't work even with Limit to list set to no or false. This sku list has thousands of choices in it, any ideas on how to incorporate the ability to search with a wildcard (eg. "ADD*") or by the combo box listing in the same report?

View 3 Replies View Related

Modules & VBA :: File Open Dialog Does Not Allow Selection Of All File Types

Oct 4, 2013

I recently upgraded a DB from 2003 to 2013 and ran into the following problem.

I have a button that opens a file dialog box and allows the user to upload a file to a predetermined location (and store the address as a hyperlink). I borrowed this code from someone else on here and modified it slightly.

In any case, the button still works, but now when it opens it doesn't have an option for "All files" under file types. So I can upload MS Office files, text files, etc., but not PDF files which are by far the most common types my users upload.

Here's my code and a screenshot is attached.

Private Sub Command35_Click()
Dim dd As Integer
Dim fileDump As FileDialog
Set fileDump = Application.FileDialog(msoFileDialogOpen)
dd = fileDump.Show

[Code] ....

View 3 Replies View Related

Backup Current Access File Using Vba While The File Is Open

Jul 11, 2007

I have a button in the form of the current access file. What I want to do is when the user click on the button,
triggered the vba to backup current access file. But since the file is currently open, is this possible? If yes, may I know how to do it with vba?

I have tried two methods but failed:
1) Use copytofile method, but I get permission denied due to file open;
2) Use dbengine.compactdatabase method, but it also has problem if the file is open.

View 3 Replies View Related

Query For Late Payments - Partial Payment Quandry

Jan 4, 2008

Hi all:

Well, as part of my new job I get to revise a current database for a client and I am hitting a brick wall in my mind at the moment and could use some ideas thrown my way on how to deal with it.

First of all I have two tables -

Table AR_Due
AR_Due_ID - Autonumber (PK)
Entity_ID - Long Integer (FK)
AR_Due_Amt - Currency
AR_Due_Date - Date/Time
AR_Due_Waive (boolean and if checked the amt due is forgiven and not due)

Table AR_Pay
AR_Pay_ID - Autonumber (PK)
AR_Due_ID - Long Integer (FK)
AR_Pay_Date - Date/Time
AR_Pay_Amt - Currency


Now, I have to pull all AR_Due where the payments are late (past the AR_Due_Date) and have no in the Waive column and, if partial payments were made those payments can't be past the due date or else they need to be included as late (that's my main issue - trying to figure out the logic on that one).

So, any ideas on how that might be best accomplished? I need a report that shows all late payments (not counting lates more than two years ago) including any where there were partial payments made but the total partial payments were not made before the due date.

I'll take any ideas, although I might not be able to use some of them due to having to follow certain standards here (don't know all of them yet but I've kind of figured a few out based on the existing db). And, I didn't put this all together so there are some things I can't change (at least at this point), but I'm happy to get any ideas that might spark the "aha" moment :).

View 7 Replies View Related

Open Text File Using Only First 7 Characters Of File Name

Nov 7, 2013

I need to open and process the data from a text file on the network.

The first 7 characters of the file name will be the same every day.

The rest of the file name will change from day to day.

There will only be one file in the folder that has those first 7 characters.

There are a total of about 120 text files in the folder every day - give or take - including the one I need to open and read.

View 6 Replies View Related

General :: Open Save File Dialog - Select File From Text Box And Save To Selected Location

Aug 8, 2013

I need code for save dialog file ,and select the file from textbox and save it to the selected location.i have only this code and i dont know what else i can do with this because it just opens the save file dialog !

View 1 Replies View Related

Use Check Box To Open Forms

May 25, 2006

I have a main form with 2 check boxes. The title of the first box is Manufacturing and the title of the second check box is Purchased. I have 2 different forms based on the titles of the check boxes. After the user checks one of the boxes, I want the user to click a command button which opens the correct form based on the box checked.

Using the On Click for the command button, I created this code, with no success:

Dim stDocName As String

If Me.Check14 = 1 Then
stDocName = "frmManufacture"
DoCmd.OpenForm stDocName
Else
If Me.Check16 = 2 Then
stDocName = "frmPurchase"
DoCmd.OpenForm stDocName
Else
stDocName = "frmError"
DoCmd.OpenForm stDocName
End If

End Sub

Thanks for helping with this problem.

Jeff

View 2 Replies View Related

Check If A Form Is Open.

Sep 7, 2006

Hello everyone,

I have a question:

I have a form in wich I can add and edit employees.
I can open this "employee" form in 2 ways:
1. From another form
2. From the mainmenu

When I close the "employee" form I want to check if the otherform (1.) is open. If it is open I want to requery the other form. If it is closed I don't want to requery the other form.
How can I check if the other form is open?

I hope that you guys can help me and thanks in advance,
Johnny

View 5 Replies View Related

How I Can Check If Form Is Open

Mar 10, 2005

How i can check if form is open ??? sorry for noob question

I want check with VB if form is open or close ???
How i can do it???

example in VC++
if(!dialog.IsOpen())
{
...
}
else
{
...
}

View 5 Replies View Related

Check If A Record Is Open With A Recordset

Jul 4, 2007

hey guys

having a corruption issue with my database, it happens when a user updates a record and a second user has that record open elsewhere. then when the second user closes they save their changes over the top, corrupting the whole record.

so i need to know with a recordset if there is a way to check if a second user is currently looking at the same record?

thanks

View 4 Replies View Related

Check For File Updates

Mar 10, 2008

When I open a form, I want it to automatically check to see if there is are any updated files. I already have imported files into Access, but want to automatically check to see weather there have been any updates to the files.

Example

Form opens,
Checks the “C:MyDouments” for any updated Excel Spreadsheets (This could be done by the modify date and time),
Imports the updated Excel Spreadsheet into Access

End

If the code checks the Modify date and time of a excel file, how can I import these values into Access i.e. I could have some query that would check the date and time of an excel file against the date and time in the access table – and if different import the latest version.

Also check for any new files.


Any ideas or help would be much appreciated

View 2 Replies View Related

Check To See If A Table Is Already Open On A Click Event

Feb 4, 2005

Some of the things that bring me screeching halt really surprise me. I swear, this sounds like it should be so easy....

What I need to do is check, when the user clicks on a button, whether a specific table that is going to be modified/deleted later in the click code is already open. If it is open, I will msgbox the user to close the table first and exit the sub.

Any ideas?

All help, as always, is much appreciated!

John

View 4 Replies View Related

Modules & VBA :: Check Outlook Is Open Not Working?

May 21, 2014

My application relies on whether Outlook is open and more importantly, with the correct Exchange profile selected. To ensure this I have the following code which, on the work PCs (Windows XP and Office 2003) works correctly.

Code:

If Outlook_is_Running = True Then
Set myOlApp = CreateObject("Outlook.Application", "localhost")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set colFolders = myNameSpace.Folders
On Error Resume Next

[code]....

The work PCs are being upgraded soon to Windows 7 and Office 2007 so I have taken the application home and started to develop it on my home PC (Windows 8.1 64 and Office 2013 64). I have used PtrSafe where necessary and have compiled with no errors, but this code always returns false even though Outlook 2013 is open.

On further investigation, if I comment out the 'On Error Resume Next line I get the error Active X component cannot create the object (or similar) Error 429. This is the same regardless of whether Outlook is open or not

View 4 Replies View Related

Modules & VBA :: Check If Directory Is Open Before Saving PDF

Aug 28, 2013

I have some code that resides in a button on a report that allows me to save a PDF version of this report. My problem is that if i have the destination directory open on windows explorer, i get a runtime 2501 "The output To action was cancelled" error.Is there any way to check if the directory is already open, and cancel the output to, or close the window to avoid this error?

Here is my code:

Code:
Private Sub CmdSavePDF_Click()
Dim MyFileName As String
Dim MyPath As String
'Dim CompanyName As String

[code]...

View 1 Replies View Related

Modules & VBA :: Lock Check Box On Open Form

Jun 29, 2015

I'm trying to lock a checkbox when the forms open and depending if one has role as admin, it should unlock it.When I add the below code in the on open form I get error:

Code:
Me.lock_case_admin.Locked = True
Me.lock_case_admin.BackColor = 12632256

This is the part that should onlock if it is admin:

Code:
Me.lock_case_admin.Locked = False
Me.lock_case_admin.BackColor = 16777215

Maybe it is me, or the checkbox is giving the error that causes the dialogbox to open to to choose the ID nr.

View 5 Replies View Related

General :: Check If File Exists?

Nov 27, 2013

I have a table with several thousand records. Each record as a path field that indicates a specific file that is associated with a given record (not just a directory, it identifies a specific file). I'm pretty sure that most of them are correct but I've seen and been cleaning up paths that have had typos in them or were otherwise not setup correctly. Is there a way that I can generate a report or a list of some sort that would tell me exactly which file paths exist and which ones don't? or even just the ones that don't.

View 4 Replies View Related

Modules & VBA :: Check If Database Is Open (Read Only Mode)

Jul 16, 2015

I would like to be able to check if a db is open and if it is to prevent the user from proceeding.

I use the Access 2013 Runtime. I can check if a db is open by trying to open Exclusively, using something like

Code: [URL] ....

But if the db is already open Not exclusively and I try to open it exclusively it does not raise an error and it allows the user to open the db in Read Only mode.

I would like to be able to prevent this, because careless and/or inexperienced users may open several instances of the db.

Of course, if the db is already open exclusively it does not allow you to open it exclusively another time.

View 5 Replies View Related

Modules & VBA :: How To Check If Field Value Exists Using Open Recordset

Nov 25, 2014

I am storing values of pictures and the location of them in a table, this works fine!... using OpenRecordset. The problem is that when the function is called to store the information, it just keeps adding the same values of each file in the folder over and over again in a word "Duplicating" the information.

I have tried various methods using the OpenRecordset, but cannot seem to find the correct manor of applying the code.

Below is the function I have for storing the data...

Code:
Public Sub GetFilesNamesFromFolder(strFolderPath As String)
On Error GoTo ErrorHandler
Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.folder
Dim objFile As Scripting.File

[Code] .....

View 12 Replies View Related

Forms :: Data Input To Check And Open Second Form

May 15, 2013

I have a form called frmStartTimeEntry where a user inputs data using a barcode scanner. In this form there is a field called Part_No where after a value is inserted, I'd like the form to check if table_lines_per_part includes this part. If not found, then I'd like the form to open another form called frmLinesPerPart where the form would pull the same Part_No inserted in the previous form to fill in the Part_No field (which is hidden) and then the user would type in a qty for the LinesPerOrder. A user would then click a button btnOk to append this new record to table_lines_per_part and be returned to the frmStartTimeEntry to continue filling out the rest of the form.

This is the idea I have but I don't know how to code the part where the form checks after update if the part_no exists in the other table, nor how to capture the part_no to the other form and then append both the part_no and the lines per part to the other table.

View 2 Replies View Related

Reports :: Set Unbound Check Box To False On Open Not Working

Dec 3, 2013

I have a report with an unbound checkbox which has a null (greyed out value) when printed. I'm just trying to set it to false when the report opens.I have

Code:
Private Sub Report_Open(Cancel As Integer)
Me.CheckNotPaid = False
End Sub

but it just says 'Runtime Error -214..You can't assign a value to this object'

View 3 Replies View Related

Check If File Exists And Replacing Files

Oct 27, 2005

hey guys

i'm trying to do something that i thought would be pretty simple. what happens is i have 2 files that get used, one by access and one by excel. they are both the same, except if one gets modified then the other doesnt obviously. (theres reasons for having the 2 files).

anyway. in access i want it to pick the newer of the two files (i assume this is using a fso system object?), if the one it normally doesnt use is newer, it should copy the new one over the old one and continue using the one it normally uses.

i cant simply use the other file as another user always has that file open.

any sample code on how to check if things are modifyed at a later date? and copy/pasting using those fso objects?

cheers guys

aaron

View 2 Replies View Related

Modules & VBA :: Check If File Exists In Database Or Not

Nov 4, 2013

I have code working for some workers here ,who used to save excel files in a folder and my databse upload those files into database and then do the rest.I am looking for a code in vba which,on upload button matches the file in table and if the file already exists ,it should not upload again in the table and if it does not exists it should upload . I have attached my code below :

Private Sub Command0_Click()
Dim strcPath As String
strcPath = "O:QA FilesQC ReportingPending Review"
Dim strcNewPath As String

strcNewPath = "O:QA FilesQC ReportingMovedFiles" & Format(Now, "yyyy-mm-dd h-mm-ss") _
& " Excel Files" & ""

[Code] .....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved