• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

transfer file programatically

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
Serena2345
Asked:
Serena2345
  • 5
  • 5
1 Solution
 
Rey Obrero (Capricorn1)Commented:
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
 
als315Commented:
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
 
Serena2345Author Commented:
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
Rey Obrero (Capricorn1)Commented:
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
 
Serena2345Author Commented:
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
 
Rey Obrero (Capricorn1)Commented:
do you really have a table with name beginning with  PRWBBEPI_ ?

can you upload a copy of the db?
0
 
Serena2345Author Commented:
Here is a screen print of my tables. I will make a copy of the db tomorrow
tables.doc
0
 
Rey Obrero (Capricorn1)Commented:
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
 
Serena2345Author Commented:
I get the 2 messages How do call the function to move the file
0
 
Rey Obrero (Capricorn1)Commented:
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
 
Serena2345Author Commented:
I got it to work Thanks Cappie
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now