fmew
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
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
typo, it should be
If nz(ba_Stat_Bp_4.Value,"") = "" Then
ba_Stat_Bp_4.Visible = False
If nz(ba_Stat_Bp_4.Value,"") = "" Then
ba_Stat_Bp_4.Visible = False
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
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
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
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
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 >
E.g. If IsNull(ba_Stat_Bp_4.Value)
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.
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.
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
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you all.
Mike and LSM, I will split points. You both helped me to get things clear and done
Erik
Mike and LSM, I will split points. You both helped me to get things clear and done
Erik
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
can you try your sql query to be tuned.
Select * from P_BA where ba_Stat_Bp_4 is not null
If nz(ba_Stat_Bp_4.Value,"") Then
ba_Stat_Bp_4.Visible = False
.... etc