|
-
Feb 14th, 2003, 04:33 PM
#1
Thread Starter
Frenzied Member
*RESOLVED*Whats wrong with my code- Please have a look!!
Here;s my code and I get am error: NEXT WITHOUT FOR...pls have a look...
VB Code:
n = 0
conDB
Set oRs = New Recordset
strSql = "Select * from Transactions where Status='Unpaid'"
oRs.Open strSql, goCnn, adOpenKeyset, adLockOptimistic, adCmdText
x = oRs.RecordCount
axn
Do While Not oRs.EOF
strItem = oRs("Group Name")
Set oRst = New Recordset
strsql1 = "Select * from Transactions where [Group Name]='" & strItem & "'" & " And status='Unpaid'"
oRst.Open strsql1, axnCnn, adOpenKeyset, adLockOptimistic
Set oRsy = New Recordset
strsql2 = "Select * from Groups where [Group Name]='" & strItem & "'"
oRsy.Open strsql2, axnCnn, adOpenKeyset, adLockOptimistic
y = oRst.RecordCount
For i = 1 To y
If n = 0 Then
Set WordObject = CreateObject("Word.Application")
With WordObject
.Application.Documents.Add App.Path & "\Invoice.dot"
.Visible = True
.Activate
.ActiveDocument.Bookmarks("Date").Range.InsertAfter Format(Date, "DD/MM/YYYY")
.ActiveDocument.Bookmarks("GROUPNAME").Range.InsertAfter oRst("Group Name")
.ActiveDocument.Bookmarks("GROUPID").Range.InsertAfter oRst("GroupID")
.ActiveDocument.Bookmarks("Address").Range.InsertAfter oRsy("Address")
.ActiveDocument.Bookmarks("TELEPHONE").Range.InsertAfter oRsy("Phone")
.Selection.MoveDown wdLine, 17
.Selection.MoveLeft wdCharacter, 2
Do While oRst.EOF = False
.Selection.TypeText oRst!Invoice_ID
.Selection.MoveRight wdCharacter, 1
.Selection.TypeText oRst!VisitDate
.Selection.MoveRight wdCharacter, 1
.Selection.TypeText oRst!TreatMent
.Selection.MoveRight wdCharacter, 1
.Selection.TypeText oRst!AmountCharged
.Selection.MoveRight wdCharacter, 1
.Selection.TypeText oRst!AmountPaid
.Selection.MoveRight wdCharacter, 1
.Selection.TypeText oRst!AmountToPay
.Selection.MoveRight wdCharacter, 1
.Selection.TypeText oRst!Status
oRst.MoveNext
If oRst.EOF = False Then
.Application.ActiveDocument.Tables(2).Rows.Add
.Selection.MoveDown wdLine, 1
.Selection.MoveLeft wdCharacter, 6
End If
Loop
Next
End With
End If
Last edited by mxnmx; Feb 14th, 2003 at 07:05 PM.
-
Feb 14th, 2003, 04:35 PM
#2
You need to swap the NEXT and the End With statements at the bottom of the code.
-
Feb 14th, 2003, 04:38 PM
#3
Thread Starter
Frenzied Member
Thanks Shaggy, that does not work...
-
Feb 14th, 2003, 04:39 PM
#4
PowerPoster
it doesn't work because he found a glaring error and didn't look beyond it. ALL of your loop control is screwed up.
Do proper indentation of your code and then look to see that for matches next and do matches loop and so forth.
-
Feb 14th, 2003, 04:51 PM
#5
You're right Phinds, those last lines are all scrambled.
If you indent each section of code, and get stuck with a problem like this, you can put your caret at the beginning of each control line, and down error to the end of that level of indentation to see if you close with the correct word. In this case, I saw that the NEXT was inside the End With, and looked no further, since the For was outside the With. In fact, the for is outside the If statement as well, so the End If must be moved inside the NEXT.
The last three lines should be:
End With
End If
Next
-
Feb 14th, 2003, 07:05 PM
#6
Thread Starter
Frenzied Member
Thanks phinds & shaggy...
I sorted it, was just a silly mistake...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|