Solved

Whille loop not going to next script text file.

Posted on 2011-09-20
3
269 Views
Last Modified: 2012-05-12
I think Its me, but the below simply repeatedly loops through and gets only the first script.  I am a little puzzled as to how to tell it to go to the next script text file, it is my understand the While should do it, but I think I messed up teh code and can't get it to work.
Private Sub Recovery()
'Recovers objects for a specific database.
Dim txtPath
Dim txtFile
Dim strObjectName As String

txtPath = "K:\DatabaseDevelopment\DBScripts_RegE\"
txtFile = Dir(txtPath & "*.txt")

While txtFile <> ""
   Select Case Left(txtFile, InStr(txtFile, "_") - 1)
         Case "Form"
            strObjectName = Left(Mid(txtFile, InStr(1, txtFile, "_") + 1), InStr(1, Mid(txtFile, InStr(1, txtFile, "_") + 1), ".") - 1)
            Application.LoadFromText acForm, strObjectName, txtPath & txtFile
            MsgBox "Form: " & strObjectName & " has been imported.", vbOKOnly
         Case "Table"

         'etc...
   End Select
Wend

End Sub

Open in new window

0
Comment
Question by:ssmith94015
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 36568231


While txtFile <> ""
   Select Case Left(txtFile, InStr(txtFile, "_") - 1)
         Case "Form"
            strObjectName = Left(Mid(txtFile, InStr(1, txtFile, "_") + 1), InStr(1, Mid(txtFile, InStr(1, txtFile, "_") + 1), ".") - 1)
            Application.LoadFromText acForm, strObjectName, txtPath & txtFile
            MsgBox "Form: " & strObjectName & " has been imported.", vbOKOnly
         Case "Table"

         'etc...
   End Select

     txtFile=dir  'ADD this
Wend
0
 
LVL 52

Expert Comment

by:Huseyin KAHRAMAN
ID: 36568306
have a look at this link to get more info on Dir() usage:

http://www.techonthenet.com/access/functions/file/dir.php

MS Access: Dir Function : Dir [( path [, attributes ] ) ]

Dir function returns the first filename that matches the pathname and attributes specified. To retrieve additional filenames that match pathname and attributes, call Dir again with no arguments.



0
 

Author Closing Comment

by:ssmith94015
ID: 36568361
Cap, that was it.  Thank you both.

Sandra
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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