Looping REcords on a form (1 Viewer)

msp

Registered User.
Local time
Today, 08:15
Joined
Apr 5, 2004
Messages
155
I am attempting to export data from my database and create separate data files for each record.

I have created a form, and I am attempting to export all the records in the filter applied on that form. (This would depend on the dataset required at the time).

I have attempted to do this by creating a “Do Loop” as shown below.

Private Sub Command101_Click()
On Error GoTo Err_Command101_Click


Dim stDocName As String
Dim stDocName2 As String

stDocName = "HLA Server Questionnaire"

Do While Not acLast

DoCmd.GoToRecord , , acNext
stDocName2 = "HLA Server Questionnaire " & [Server_Name] & " - " & Date$ & ".xls"
DoCmd.OutputTo acReport, stDocName, acFormatXLS, stDocName2, True

Loop

Exit_Command101_Click:
Exit Sub

Err_Command101_Click:
MsgBox Err.Description
Resume Exit_Command101_Click

Whilst the code above does work, I know the loop is not really working, does anyone have any suggestions as to how to get my loop working correctly. – Thanks
 

msp

Registered User.
Local time
Today, 08:15
Joined
Apr 5, 2004
Messages
155
I have now managed to get this to work using CurrentRecord
 
C

cshark

Guest
How to use CurrentRecord

This sounds exactly what I am looking for, but my VB is very poor. How did you use CurrentRecord? What was the code that you used and where did you put it? I would really, really appreciated it if you would be able to help !!!

Thanks,

Carrie
 

Users who are viewing this thread

Top Bottom