Solved

transfer file programatically

Posted on 2012-03-29
11
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

739 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