Link to home
Create AccountLog in
Avatar of fmew
fmewFlag for Netherlands

asked on

Do while, loop etc

Hi there,

I am trying to adjust

Private Sub Form_Timer()

   Dim strSql As String

    strSql = " Select * from P_BA"
 
    Set db = CurrentDb
    Set rs = db.OpenRecordset(strSql, dbOpenDynaset)

Do While Not rs.EOF
   
       If ba_Stat_Bp_4.Value Is Null Then
             ba_Stat_Bp_4.Visible = False

      Else

       rs.MoveNext
       End If

Exit Do
Loop
rs.Close
Set rs = Nothing
Set db = Nothing

End Sub

So its about the:
       If ba_Stat_Bp_4.Value Is Null Then
             ba_Stat_Bp_4.Visible = False
This doesnt work. In fact I tried other code. Nothiing works. I just can not do it.
What kind of code should I use to let this go to the recordset

Erik
Avatar of frankytee
frankytee
Flag of Australia image

try
If nz(ba_Stat_Bp_4.Value,"") Then
             ba_Stat_Bp_4.Visible = False

.... etc
typo, it should be
If nz(ba_Stat_Bp_4.Value,"") = "" Then
             ba_Stat_Bp_4.Visible = False
Avatar of fmew

ASKER

Hi,
Problem is the code stops at If Nz(ba_Stat_Bp_4.Value, "") = "" Then
No error, just stops
So thats something in my loop?

Erik
Avatar of fmew

ASKER

Its because the first value it finds is ba_Stat_Bp_4.Value, "") = "E"
When I change the first record to E, the code runs , but makes all the  ba_Stat_Bp_4 field invisible, incluis the ones which are empty
Avatar of Scott McDaniel (EE MVE )
What exactly are you trying to do with this code? Please tell us what the loop is supposed to do ...
The IS NULL sysntax applies only to objects. For normal values you can use the IsNull() function:
E.g. If IsNull(ba_Stat_Bp_4.Value) Then

You can set the visible property in a single step without an IF statement:

ba_Stat_Bp_4.Visible = not IsNull(ba_Stat_Bp_4.Value)

The loop doen't look quite right:    
<    Do While Not rs.EOF
         If ba_Stat_Bp_4.Value Is Null Then
             ba_Stat_Bp_4.Visible = False
         Else
             rs.MoveNext      ' <======= this will never execute after a null is found
         End If
         Exit Do                   ' <======= exits the loop first time through
    Loop >
LMSConsulting:
Yes, that was the next point, It looks like an attempt to show/hide a control on different rows of a continuous form, which won't in any case work via the visible property of the control.
Avatar of fmew

ASKER

Yes MikeToole,
Thats what Iam trying to do.
But it hasnt have to be a visible property, it may be something else
The field maybe Null, I can change the default to say .  So theres a value than.
The loop would work then? Still not with the visible property?


Erik
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of fmew

ASKER

Thank you all.

Mike and LSM, I will split points. You both helped me to get things clear and done

Erik
Avatar of bhushanvinay
bhushanvinay

i dont know if i make sense

can you try your sql query to be tuned.


Select * from P_BA where ba_Stat_Bp_4 is not null