Solved

transfer file programatically

Posted on 2012-03-29
11
246 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
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 39

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
 
LVL 119

Expert Comment

by:Rey Obrero
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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 119

Accepted Solution

by:
Rey Obrero 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

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)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HasData 9 36
Like Function in Query Dramatically Increasing Run Time 13 32
MS accesss using VBA to change a default value 5 28
Two list boxes - best structure 3 31
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

912 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

26 Experts available now in Live!

Get 1:1 Help Now