Looping Left function has me stumped

pensived

Registered User.
Local time
Yesterday, 22:55
Joined
Feb 22, 2012
Messages
11
Hello Everyone,

I have a sub-form in datasheet view with several records, the first two characters of each record make up a product code, that is then copied to a field on the parent form. I can split the first two characters from the first record. I've tried everything I can think of to loop through, but I'm missing something. I get the first two letters of the first line X the number of lines. I get "PM X 4" PMPMPMPM



Code:
Private Sub Command84_Click()
Dim rst As DAO.Recordset
Dim sTmp As String
Set rst = Me.[PanelBuild].Form.RecordsetClone

With rst
  Do Until .EOF
    sTmp = sTmp & Left([Forms]![panelbuilder]![PanelBuild]![subCode], 2)
    .MoveNext
  Loop
End With

rst.Close
Set rst = Nothing

Me.Text82 = sTmp

End Sub


Any help would greatly appreciated. Thank you
 

Attachments

  • Untitled.png
    Untitled.png
    97.7 KB · Views: 59
  • Capture.PNG
    Capture.PNG
    8.8 KB · Views: 70
Last edited:
You're looping through the recordset but you're not using the data in the recordset.
 
I'm sorry, but I don't understand? I'm getting data, but only from the first record over and over again.
 
You're getting text from this textbox "subCode" but you're not getting data from the recordset. Think of a recordset like a table. Use the Fields() method (i.e. rst.Fields("FieldName")) or rs!FieldName of the recordset to get the field data you want.
 
I've tried changing Me.[PanelBuild].Form.RecordsetClone to include the field on the subform, but I don't think the syntax is right?
 
Code:
With rst
  Do Until .EOF
[COLOR="Green"]    'use a field from your cloned recordset, not the subform . . .[/COLOR]
    sTmp = sTmp & Left(.fields("subCode"), 2)
    .MoveNext
  Loop
End With
 
Oh man, that's why I couldn't get it! I was focused on the subform! Thank you so much. Too many hours staring at a screen, makes for permanent brain farts.

Thank you again.!
 
Oh man, that's why I couldn't get it! I was focused on the subform! Thank you so much. Too many hours staring at a screen, makes for permanent brain farts.

Thank you again.!
I would advise that you also look at the link provided. It will give you some basic insight into the use of recordsets.
 

Users who are viewing this thread

Back
Top Bottom