Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving a File

Status
Not open for further replies.

anon1971

Programmer
Aug 9, 2008
88
US
I am tring to move a file from one folder to the next and I know what the file is I just cant get the code to work. Mis match error. Thanks for any lioght on this

temp = getLastTIF("\\192.168.0.101\_file cabnet\temp\")
obj = Right(temp, Len(temp) - InStrRev(temp, "\"))
FilePath = "\\192.168.0.101\_file cabnet\" & Right(temp, Len(temp) - InStrRev(temp, "\"))

Set Object = obj
Object.MoveFile("\\192.168.0.101\_file cabnet\temp\", "\\192.168.0.101\_file cabnet\") = 1
 
I can't see your variable declarations so it is entirely possible that this "Set Object = obj" is not correct.

So, if you want to move them you should be able to just use:
Code:
Name OriginalPathAndFileNameHere As NewPathAndFileNameHere

Also, you need to include the file name in your paths there. You don't just use the folder names.

Bob Larson
Free Access Tutorials and Samples:
 
I got it to work. IO was trying to speed up our scanning indexing by putting the file in a temp folder and moving it to the file fold and it speeds up every scann by 45 seconds wow. Here it is if anyone needs it.

Dim stAppName As String
Dim fso
stAppName = """C:\Program Files\Common Files\Microsoft Shared\MSPaper\MSPSCAN.EXE"" Scan"
CreateObject("WScript.Shell").Run stAppName, 1, True
temp = getLastTIF("\\192.168.0.101\_file cabnet\temp\")
FilePath = "\\192.168.0.101\_file cabnet\" & Right(temp, Len(temp) - InStrRev(temp, "\"))

Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile temp, "\\192.168.0.101\_file cabnet\"


Set rst = CurrentDb.OpenRecordset("Scan", dbOpenDynaset, dbSeeChanges)

rst.AddNew
rst![FileID].Value = Me.ProjectID 'use the name of the field for your date in your table
rst![FileName].Value = Me.Scan_Description
rst![FileDate].Value = Now()
rst![FilePath].Value = FilePath
rst.Update
rst.Close

 
Thanks bob I got it posted above. Oh here is the entire code if anyone needs a really good scanning scrip to use with MS document scanning.


Private Sub Scan_Click()
If Me.Wait = "Please wait scan in progress......" Then
MsgBox "<<Warning!>> Scan in progress please wait!"
Me.Scan_Description.SetFocus
End
End If
'--

If IsNull(Me.Scan_Description) Then
MsgBox "<<Warning!>> Description Required!"
Me.Scan_Description.SetFocus
End
End If
'--

If InputBox("Please enter your password") = DLookup("[SupervisorPassword]", "Company", "[CompanyID] = 907927") Then
Else
MsgBox "Incorrect Password"
Me.Scan.SetFocus
End
End If
'--

Me.Wait = "Please wait scan in progress......"
Me.ProjectID.SetFocus
'--

Dim stAppName As String
Dim fso
stAppName = """C:\Program Files\Common Files\Microsoft Shared\MSPaper\MSPSCAN.EXE"" Scan"
CreateObject("WScript.Shell").Run stAppName, 1, True
temp = getLastTIF("\\192.168.0.101\_file cabnet\temp\")
FilePath = "\\192.168.0.101\_file cabnet\" & Right(temp, Len(temp) - InStrRev(temp, "\"))

Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile temp, "\\192.168.0.101\_file cabnet\"


Set rst = CurrentDb.OpenRecordset("Scan", dbOpenDynaset, dbSeeChanges)

rst.AddNew
rst![FileID].Value = Me.ProjectID 'use the name of the field for your date in your table
rst![FileName].Value = Me.Scan_Description
rst![FileDate].Value = Now()
rst![FilePath].Value = FilePath
rst.Update
rst.Close
'--

DoCmd.Close
End Sub
 
getLastTiff

Function getLastTIF(strPath As String) As String
Dim fso, d, f
Dim dc As Date
Dim fp As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set d = fso.GetFolder(strPath)
For Each f In d.Files
If Right(UCase(f.Name), 4) = ".TIF" _
And f.DateCreated > dc Then
fp = f.path: dc = f.DateCreated
End If
Next
getLastTIF = fp
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top