[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Whille loop not going to next script text file.

Posted on 2011-09-20
3
Medium Priority
?
281 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 2000 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 61

Expert Comment

by:HainKurt
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

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!

Question has a verified solution.

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

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

873 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