Help loop recordset

M

Maarkr

I've got about 30 images to loop thru by checking if it's in the recordset
then make it visible if it's in the [LOC] field... this works but can u
suggest how to get my ten varying values from the [loc] field (like W-1, W-2,
N-1...) to match one of the 30 images... I can use any name for the image, in
this case it was W1, W2...
I just didn't want to use 30 instances of then If-Then routine.
Function DAORecEx()
Dim rs As DAO.Recordset
Dim strSql As String, strPSpot As String

strSql = "SELECT LOC FROM tblStatus;"
Set rs = DBEngine(0)(0).OpenRecordset(strSql)

Do While Not rs.EOF
'Debug.Print rs!Loc
strPSpot = rs![Loc]
If strPSpot = "W-1" Then
Me.W1.Visible = True
End If
If strPSpot = "W-2" Then
Me.W2.Visible = True
End If
rs.MoveNext
Loop

rs.Close
Set rs = Nothing
End Function
 
M

Mike Painter

Me.left(strPSpot,1) & Right(strPSpot,1).visible = True
or just get rid of the "-" in your data.
 
S

Steve Sanford

This is untested......
(see http://www.mvps.org/access/forms/frm0003.htm)


Function DAORecEx()
Dim rs As DAO.Recordset
Dim strSql As String, strPSpot As String
Dim k As Integer ' counter

strSql = "SELECT LOC FROM tblStatus;"
' Set rs = DBEngine(0)(0).OpenRecordset(strSql)

Set rs = CurrentDb.OpenRecordset(strSql)

' initialize
k = 1

Do While Not rs.EOF
'Debug.Print rs!Loc
strPSpot = rs![Loc]

If strPSpot = "W-" & k Then
Me("W" & k).Visible = True
End If

'increment
k = k + 1

rs.MoveNext
Loop

rs.Close
Set rs = Nothing
End Function


HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top