Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Do Loop does not work

Do Loop does not work

Do Loop does not work

I am a newbie and can't decide what I'm doing wrong.
refsql = "select Quantity_owned, Current_Val, symbol, Dont_record from [Stock_Data]" 'Fields(0) = Quanity, Fields(1)= Current Value, field(2) = symbol
Set rstStkD = CurrentDb.OpenRecordset(refsql, dbOpenDynaset)
C = 0
cv = 0 'Current Value
Tot = 0 'Total
s = "S" 'Symbol

Do While Not rstStkD.EOF
'If (rstStkD.Fields(3)) = -1 Then

If IsNull(rstStkD.Fields(1)) Then
If rstStkD.Fields(3) = "false" Then

'Debug.Print rstStkD.Fields(3)
msg = "The current sock value is missing for " & rstStkD.Fields(2) & ". Make sure closed stock positions indicate a current value and are not deleted."
X = MsgBox(msg, vbOKOnly)
Exit Sub
End If
End If
q = rstStkD.Fields(0) 'Quanity
cv = rstStkD.Fields(1)
Tot = Tot + q * cv
s = rstStkD.Fields(2)

I wrote this as past od a DB to record activities in my portfolio. I won't to display a message when I forgot to include a particular stock. However, there are some I don't won't to display. Field three is a check box. When checked I don't want Access to record the information. However, if the name is missing and the box is checked, Access kicks me out of the loop with out continuing to record the rest of the data. Everything seems to work until it reaches the "Tot = Tot + q * cv" statement. Again, this only happens when the box is checked and the name is missing. Any other combination seems to work!
Thanks for your help. You people are great!!


RE: Do Loop does not work


Are you sure that field(3) is data type String and not Boolean?

You've been around Tek-Tips for some seventeen years. So why aren't you using TGML codes to display your code like...


If rstStkD.Fields(3) = "false" Then

Also you won't want to assign variables like q, cv, tot and s without using them in some useful manner.


glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Do Loop does not work

>Everything seems to work until it reaches the "Tot = Tot + q * cv" statement

And what happens at that point?

RE: Do Loop does not work

Thanks for the responses.
Field(3) is a check box on a form. I have tried to express the statement as "If rstStkD.Fields(3) = -1 Then". I get the same results. And "q, cv, tot and s" are used later in the logic.

The program jumps out of the loop and exits to the calling statements. The is a subroutine called "Get_Tot". When this happens, the program jumps to the statement after "get_tot".

The whole routine works properly when either of the "if" statements are false. is there some rule against nesting more then one If Statement in a Do Loop?

RE: Do Loop does not work

Regarding your CheckBox, it is a Boolean, either TRUE or FALSE (which is NOT "true" or "false").

So if you want the TRUE result...


If rstStkD.Fields(3) Then
...or if you want the FALSE result...


If Not rstStkD.Fields(3) Then


glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Do Loop does not work

>The program jumps out of the loop and exits to the calling statements

Which suggest that you've got an active error handler running, from the description On Error Resume Next

>If IsNull(rstStkD.Fields(1))

So we only go on if rstStkD.Fields(1) is Null. And then we assign that to cv. And then we try and multiply by cv ...

That raises an error. But since you have an error handler running, the error handler is triggered.

Disable the error handler (comment it out), and you should see the error that is actually occurring (which will probably be Error 94)

RE: Do Loop does not work

Thanks. I also had one other problem but I would have never found it if I didn't get that one!
Yes I have been a member for 17 years, but I am, as you can tell still a novice/ newbie! Don't get much of a chance to do programming and never had any training. That is why I really appreciate yours and the others help!
Thank you again! Bill

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close