DoCmd.GoToRecord Question

M

Michael Banks

Is there a way after I run a SQL string to create a sub-recordsource on
a subfrm to have the code goto a specific line in recordsource?

What I would like to do is cycle through the records in the recordsource
looking only in the row that it is currently in for a specific piece of
text?

My current attempt looks like:

Private Sub cboGLN_AfterUpdate()
Dim i As Long
Dim k As String
Dim j As String
Dim rsCount As Integer

Me!txtRecordSetCount = ""
rsCount = 0
InteriorCount = 1

Set rs = Me!subfrmPhoto.Form.RecordsetClone
Me![txtRecordSetCount] = rs.RecordCount

' k = DLookup("Location", "dbo_tblFormData", "GLN = '" & cboGLN &
"'")
' i = InStr(1, k, cboGLN)
' i = i + 12
' j = Left(k, i)

' Forms!frmphoto!subfrmPhoto.Form.RecordSource = "SELECT * from
dbo_tblFormData where [Location] like '" & j & "*'"

Do While rsCount <= txtRecordSetCount
DoCmd.GoToRecord , , acNext, 1

k = DLookup("Location", "dbo_tblFormData", "GLN = '" &
cboGLN & "'")
i = InStr(1, k, cboGLN)
i = i + 12
j = Left(k, i)

Forms!frmphoto!subfrmPhoto.Form.RecordSource = "SELECT *
from dbo_tblFormData where [Location] like '" & j & "*'"
Forms!frmphoto!subfrmPhoto.Form!ImageFrame.Picture =
Forms!frmphoto!subfrmPhoto.Form![txtLocation]
Debug.Print Forms!frmphoto!subfrmPhoto.Form![txtLocation]
InteriorCount = InteriorCount + 1
rsCount = rsCount + 1
Loop
Call DisplayPictures
End Sub

I would like to able to perform the DLookup only on the record that I am
currently in.

Thanks for your help.
Mike
 
K

Ken Snell

I believe that your code is trying to move you through the recordset and not
the recordsetclone. However, you didn't set the focus to the subform before
doing the loop, so it's trying to loop through the main form's recordset. Is
that what you want? Doesn't seem that way, as you're using the subform to
get the number of records that you want to cycle through?
 

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