Solved

transfer file programatically

Posted on 2012-03-29
11
250 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37782436
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 40

Expert Comment

by:als315
ID: 37782465
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
ID: 37782528
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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37782628
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
ID: 37783128
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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37783221
do you really have a table with name beginning with  PRWBBEPI_ ?

can you upload a copy of the db?
0
 

Author Comment

by:Serena2345
ID: 37783273
Here is a screen print of my tables. I will make a copy of the db tomorrow
tables.doc
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37783325
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
ID: 37832787
I get the 2 messages How do call the function to move the file
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 37832854
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
ID: 37834507
I got it to work Thanks Cappie
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

680 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