Looping Left function has me stumped (1 Viewer)

pensived

Registered User.
Local time
Today, 13:57
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: 41
  • Capture.PNG
    Capture.PNG
    8.8 KB · Views: 54
Last edited:

vbaInet

AWF VIP
Local time
Today, 21:57
Joined
Jan 22, 2010
Messages
26,374
You're looping through the recordset but you're not using the data in the recordset.
 

pensived

Registered User.
Local time
Today, 13:57
Joined
Feb 22, 2012
Messages
11
I'm sorry, but I don't understand? I'm getting data, but only from the first record over and over again.
 

vbaInet

AWF VIP
Local time
Today, 21:57
Joined
Jan 22, 2010
Messages
26,374
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.
 

pensived

Registered User.
Local time
Today, 13:57
Joined
Feb 22, 2012
Messages
11
I've tried changing Me.[PanelBuild].Form.RecordsetClone to include the field on the subform, but I don't think the syntax is right?
 

MarkK

bit cruncher
Local time
Today, 13:57
Joined
Mar 17, 2004
Messages
8,185
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
 

pensived

Registered User.
Local time
Today, 13:57
Joined
Feb 22, 2012
Messages
11
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.!
 

vbaInet

AWF VIP
Local time
Today, 21:57
Joined
Jan 22, 2010
Messages
26,374
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

Top Bottom