Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Loop Returning One Value

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Loop Returning One Value
DS <bootybox[ at ]optonline.net> 04.09.2006 20:48:59
I have this loop statement that is almost working, the problem is that
instead of starting at the first record, making it the next highest
LineID available, then going to the next and makeing that the next
LineID +1 its just finding the highest Line ID at the end of the
recordset and making all the LineID's in every record that one.
I should have this//
1
2
3
4
5
6
but I'm getting this
6
6
6
6
6
6

Any Help Appreciated,
Thanks
DS

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT * FROM SplitHold WHERE
SplitHold.SalesID = " & Me.TxtLeftID & "", dbOpenDynaset)
With rst
Do Until .EOF
Me.TxtNextLine = DMax("LineID", "SplitHold", "SalesID =
Forms!MoveItem!TxtLeftID")
Me.TxtNextLine = Me.TxtNextLine + 1
Dim NewSQL As String
DoCmd.SetWarnings False
NewSQL = "UPDATE SplitHold SET
SplitHold.LineID=Forms!MoveItem!TxtNextLine " & _
"WHERE SplitHold.SalesID = Forms!MoveItem!TxtLeftID;"
DoCmd.RunSQL (NewSQL)
DoCmd.SetWarnings True
.MoveNext
Loop
End With
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
Re: Loop Returning One Value (Edit Method Needed?)
DS <bootybox[ at ]optonline.net> 04.09.2006 21:00:13
DS wrote:
So I think this is closer but I need the Edit Method?

With rst
Do Until .EOF
Me.TxtNextLine = DMax("LineID", "SplitHold", "SalesID =
Forms!MoveItem!TxtLeftID")
Me.TxtNextLine = Me.TxtNextLine + 1
.Edit
.Update
!LineID = Me.TxtNextLine
.MoveNext
Loop
End With

Thanks
DS
Re: Loop Returning One Value
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com> 04.09.2006 21:05:35
"DS" <bootybox[ at ]optonline.net> wrote in message
news:Zi0Lg.37$fm1.14[ at ]newsfe10.lga
[Quoted Text]
> I have this loop statement that is almost working, the problem is that
> instead of starting at the first record, making it the next highest
> LineID available, then going to the next and makeing that the next
> LineID +1 its just finding the highest Line ID at the end of the
> recordset and making all the LineID's in every record that one.
> I should have this//
> 1
> 2
> 3
> 4
> 5
> 6
> but I'm getting this
> 6
> 6
> 6
> 6
> 6
> 6
>
> Any Help Appreciated,
> Thanks
> DS
>
> Dim dbs As DAO.Database
> Dim rst As DAO.Recordset
> Set dbs = CurrentDb
> Set rst = dbs.OpenRecordset("SELECT * FROM SplitHold WHERE
> SplitHold.SalesID = " & Me.TxtLeftID & "", dbOpenDynaset)
> With rst
> Do Until .EOF
> Me.TxtNextLine = DMax("LineID", "SplitHold", "SalesID =
> Forms!MoveItem!TxtLeftID")
> Me.TxtNextLine = Me.TxtNextLine + 1
> Dim NewSQL As String
> DoCmd.SetWarnings False
> NewSQL = "UPDATE SplitHold SET
> SplitHold.LineID=Forms!MoveItem!TxtNextLine " & _
> "WHERE SplitHold.SalesID = Forms!MoveItem!TxtLeftID;"
> DoCmd.RunSQL (NewSQL)
> DoCmd.SetWarnings True
> .MoveNext
> Loop
> End With
> rst.Close
> Set rst = Nothing
> dbs.Close
> Set dbs = Nothing

Pardon my saying so, DS, but that code looks a bit odd to me. What
exactly are you trying to do? As it is, it's going to repeatedly update
all the records in SplitHold with the matching SalesID, setting the
LineID of all those matching records to the latest one you calculated.
So for the last record in the recordset, you'll set all the matching
records to the last LineID you calculated.

Could you describe in words what you have and what you are trying to
accomplish? I'm pretty sure it's a lot simpler than you're making it.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Re: Loop Returning One Value (Edit Method Needed?)
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com> 04.09.2006 21:07:00
"DS" <bootybox[ at ]optonline.net> wrote in message
news:vt0Lg.38$fm1.2[ at ]newsfe10.lga
[Quoted Text]
> DS wrote:
> So I think this is closer but I need the Edit Method?
>
> With rst
> Do Until .EOF
> Me.TxtNextLine = DMax("LineID", "SplitHold", "SalesID =
> Forms!MoveItem!TxtLeftID")
> Me.TxtNextLine = Me.TxtNextLine + 1
> .Edit
> .Update
> !LineID = Me.TxtNextLine
> .MoveNext
> Loop
> End With

At the very least you need to put the .Update line after the line that
changes !LineID:

.Edit
!LineID = Me.TxtNextLine
.Update

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Re: Loop Returning One Value (Edit Method Needed?)
"J. Goddard" <jrgoddard[ at ]NO_cyberus_SPAM.ca> 04.09.2006 23:13:35
DS -

You are initializing Me!txtnextline inside your loop on each iteration;
me!txtnextline = Dmax.... should be above the Do Until... line.

As Dirk has pointed out, you need the !lineid = me!txtnextline between
the .edit and the .update.

But what are you trying to do? From what I can see from the code, all
it does is change the values for one SalesId from

4
5
6
7
8

to

9
10
11
12
13

Is that what you want?

John


DS wrote:

[Quoted Text]
> DS wrote:
> So I think this is closer but I need the Edit Method?
>
> With rst
> Do Until .EOF
> Me.TxtNextLine = DMax("LineID", "SplitHold", "SalesID =
> Forms!MoveItem!TxtLeftID")
> Me.TxtNextLine = Me.TxtNextLine + 1
> .Edit
> .Update
> !LineID = Me.TxtNextLine
> .MoveNext
> Loop
> End With
>
> Thanks
> DS

Re: Loop Returning One Value (Edit Method Needed?)
DS <bootybox[ at ]optonline.net> 05.09.2006 02:35:25
Dirk Goldgar wrote:
[Quoted Text]
> "DS" <bootybox[ at ]optonline.net> wrote in message
> news:vt0Lg.38$fm1.2[ at ]newsfe10.lga
>
>>DS wrote:
>>So I think this is closer but I need the Edit Method?
>>
>>With rst
>>Do Until .EOF
>> Me.TxtNextLine = DMax("LineID", "SplitHold", "SalesID =
>>Forms!MoveItem!TxtLeftID")
>> Me.TxtNextLine = Me.TxtNextLine + 1
>> .Edit
>> .Update
>> !LineID = Me.TxtNextLine
>> .MoveNext
>> Loop
>>End With
>
>
> At the very least you need to put the .Update line after the line that
> changes !LineID:
>
> .Edit
> !LineID = Me.TxtNextLine
> .Update
>
Yep! That did it! It was simple as you said!
Re: Loop Returning One Value (Edit Method Needed?)
DS <bootybox[ at ]optonline.net> 05.09.2006 02:37:02
J. Goddard wrote:

[Quoted Text]
> DS -
>
> You are initializing Me!txtnextline inside your loop on each iteration;
> me!txtnextline = Dmax.... should be above the Do Until... line.
>
> As Dirk has pointed out, you need the !lineid = me!txtnextline between
> the .edit and the .update.
>
> But what are you trying to do? From what I can see from the code, all
> it does is change the values for one SalesId from
>
> 4
> 5
> 6
> 7
> 8
>
> to
>
> 9
> 10
> 11
> 12
> 13
>
> Is that what you want?
>
> John
>
>
> DS wrote:
>
>> DS wrote:
>> So I think this is closer but I need the Edit Method?
>>
>> With rst
>> Do Until .EOF
>> Me.TxtNextLine = DMax("LineID", "SplitHold", "SalesID =
>> Forms!MoveItem!TxtLeftID")
>> Me.TxtNextLine = Me.TxtNextLine + 1
>> .Edit
>> .Update
>> !LineID = Me.TxtNextLine
>> .MoveNext
>> Loop
>> End With
>>
>> Thanks
>> DS
>
>
Yes that is what I want. It works now. Just had to take sometime to
work through it and also a little help from the newsgroup for good measure!
Thanks
DS

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net