Solved

transfer file programatically

Posted on 2012-03-29
11
242 Views
Last Modified: 2012-04-11
I had help on this yesterday but it is not working. First it told me I had a for without a next. After a little digging around I found out it was missing an end if. Maybe I am not putting it in the right place but I can't get it to recognize and rename the file or any of the rest

Public Sub FindFile()

Dim td As dao.TableDef, db As dao.Database, sTable As String
Set db = CurrentDb

For Each td In db.TableDefs
        If Left(td.Name, 9) = "PRWBBEPI_" Then
            sTable = td.Name
   
            MsgBox sTable
End If
           
            Send2Archive sTable
         
Next
end sub

Public Function Send2Archive(strTable As String)



 DoCmd.TransferDatabase transfertype:=acExport, _
  databasetype:="Microsoft Access", _
  databasename:="C:\Documents and Settings\mine\My Documents\destination.accdb", _
  ObjectType:=acTable, Source:="sTable", _
  Destination:="sTable", structureonly:=False
0
Comment
Question by:Serena2345
  • 5
  • 5
11 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
what is wrong?


use this code, change sTable with strTable


Public Function Send2Archive(strTable As String)



 DoCmd.TransferDatabase transfertype:=acExport, _
  databasetype:="Microsoft Access", _
  databasename:="C:\Documents and Settings\mine\My Documents\destination.accdb", _
  ObjectType:=acTable, Source:=strTable, _
  Destination:=strTable, structureonly:=False
0
 
LVL 39

Expert Comment

by:als315
Comment Utility
Try this code:
Dim td As dao.TableDef, db As dao.Database, sTable As String
Set db = CurrentDb

For Each td In db.TableDefs
        If Left(td.Name, 9) = "PRWBBEPI_" Then
            sTable = td.Name
   
            MsgBox sTable
            Send2Archive sTable
        End If
Next
end sub

Open in new window

In your code sTable was repeated for tables not started with "PRWBBEPI_"
0
 

Author Comment

by:Serena2345
Comment Utility
Public Function Send2Archive(strTable As String)



 DoCmd.TransferDatabase transfertype:=acExport, _
  databasetype:="Microsoft Access", _
  databasename:="C:\Documents and Settings\pdonichy\My Documents\destination.accdb", _
  ObjectType:=acTable, Source:="strTable", _
  Destination:="strTable", structureonly:=False
 
 
End Function



Public Sub FindFile()
Dim td As dao.TableDef, db As dao.Database, strTable As String
 Set db = CurrentDb

For Each td In db.TableDefs
        If Left(td.Name, 9) = "PRWBBEPI_" Then
            strTable = td.Name
   
            MsgBox strTable
End If
           
            Send2Archive strTable
         
Next



End Sub



There is the code this is what I get
Public Function Send2Archive(strTable As String)



 DoCmd.TransferDatabase transfertype:=acExport, _
  databasetype:="Microsoft Access", _
  databasename:="C:\Documents and Settings\pdonichy\My Documents\destination.accdb", _
  ObjectType:=acTable, Source:="strTable", _
  Destination:="strTable", structureonly:=False
 
 
End Function



Public Sub FindFile()
Dim td As dao.TableDef, db As dao.Database, strTable As String
 Set db = CurrentDb

For Each td In db.TableDefs
        If Left(td.Name, 9) = "PRWBBEPI_" Then
            strTable = td.Name
   
            MsgBox strTable
End If
           
            Send2Archive strTable
         
Next



End Sub
Public Function Send2Archive(strTable As String)



 DoCmd.TransferDatabase transfertype:=acExport, _
  databasetype:="Microsoft Access", _
  databasename:="C:\Documents and Settings\pdonichy\My Documents\destination.accdb", _
  ObjectType:=acTable, Source:="strTable", _
  Destination:="strTable", structureonly:=False
 
 
End Function



Public Sub FindFile()
Dim td As dao.TableDef, db As dao.Database, strTable As String
 Set db = CurrentDb

For Each td In db.TableDefs
        If Left(td.Name, 9) = "PRWBBEPI_" Then
            strTable = td.Name
   
            MsgBox strTable
End If
           
            Send2Archive strTable
         
Next



End Sub
See error in attachment
error1.doc
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
copy and paste ALL these codes



Public Sub FindFile()
Dim td As dao.TableDef, db As dao.Database, strTable As String
 Set db = CurrentDb

For Each td In db.TableDefs
        If Left(td.Name, 9) = "PRWBBEPI_" Then
            strTable = td.Name
   
            MsgBox strTable
      
           
            Send2Archive strTable
      End If
         
Next
End Sub


Public Function Send2Archive(strTable As String)

 DoCmd.TransferDatabase transfertype:=acExport, _
  databasetype:="Microsoft Access", _
  databasename:="C:\Documents and Settings\pdonichy\My Documents\destination.accdb", _
  ObjectType:=acTable, Source:=strTable, _
  Destination:=strTable, structureonly:=False
 
 
End Function



Note* do not enclosed strTable in quotes
0
 

Author Comment

by:Serena2345
Comment Utility
Here is what is in there . It does not work. It does not seem to recoginze the file with "PRWBBEPI_" rename it and finish the processing, even though I know it is there

Option Compare Database
Option Explicit
Public Sub FindFile()
Dim td As dao.TableDef, db As dao.Database, strTable As String
 Set db = CurrentDb

For Each td In db.TableDefs
        If Left(td.Name, 9) = "PRWBBEPI_" Then
            strTable = td.Name
   
            MsgBox strTable
     
           
            Send2Archive strTable
      End If
         
Next
End Sub


Public Function Send2Archive(strTable As String)

 DoCmd.TransferDatabase transfertype:=acExport, _
  databasetype:="Microsoft Access", _
  databasename:="C:\Documents and Settings\pdonichy\My Documents\destination.accdb", _
  ObjectType:=acTable, Source:=strTable, _
  Destination:=strTable, structureonly:=False
 
 
End Function
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
do you really have a table with name beginning with  PRWBBEPI_ ?

can you upload a copy of the db?
0
 

Author Comment

by:Serena2345
Comment Utility
Here is a screen print of my tables. I will make a copy of the db tomorrow
tables.doc
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
copy this codes and run


Public Sub FindFileX()
Dim td As dao.TableDef, db As dao.Database, strTable As String
 Set db = CurrentDb

For Each td In db.TableDefs
        If Left(td.Name, 8) = "PRWBBEPI" Then
            strTable = td.Name
   
            MsgBox strTable    
      End If        
Next
End Sub



you should get two messages
0
 

Author Comment

by:Serena2345
Comment Utility
I get the 2 messages How do call the function to move the file
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
Public Sub FindFileX()
Dim td As dao.TableDef, db As dao.Database, strTable As String
 Set db = CurrentDb

For Each td In db.TableDefs
        If Left(td.Name, 8) = "PRWBBEPI" Then
            strTable = td.Name
   
           Send2Archive(strTable)    'Add this line

      End If        
Next
End Sub

Public Function Send2Archive(strTable As String)

 DoCmd.TransferDatabase transfertype:=acExport, _
  databasetype:="Microsoft Access", _
  databasename:="C:\Documents and Settings\pdonichy\My Documents\destination.accdb", _
  ObjectType:=acTable, Source:=strTable, _
  Destination:=strTable, structureonly:=False
 
 
End Function
0
 

Author Closing Comment

by:Serena2345
Comment Utility
I got it to work Thanks Cappie
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now