D
Dan
I have tried everything that I can find on the internet, but am still unable
to get this to work. I want the following code to find records in a table
that fit a certain criteria, then copy one field from the record to a text
box. It should then move to the next record that fits the criteria and copy
it to the next text box.
Any ideas on where I am going wrong. It is currently finding the first
record and and puting that field into every text box.
Thanks,
Private Sub SL3()
Dim db As Database
Dim rst As DAO.Recordset
Dim FldNm As String
Dim Box As String
Dim strValue As String
Dim x As Integer
Set db = CurrentDb()
Set rst = db.OpenRecordset("SL3NSNDetail", dbOpenDynaset)
' FldNm = "Nomen"
Box = "txtSL3Item"
x = 0
With rst
If Not (.EOF And .BOF) Then
rst.MoveFirst
Do Until rst.EOF
For x = 1 To 3
' strValue = "Select SL3NSNDetail.[NOMEN] FROM SL3NSNDetail" & _
' "WHERE SL3NSNDetail.[ID] = '" & Forms![IssueForm]![cboWpnType1] & "'"
strValue = _
DLookup("SL3NSNDetail.[NOMEN]", "SL3NSNDetail", "[ID] = '" &
Forms![IssueForm]![cboWpnType1] & "'")
Me.Controls(Box & x).Value = strValue
rst.MoveNext
Next
Loop
End If
End With
rst.Close
Set rst = Nothing
Set db = Nothing
End Sub
to get this to work. I want the following code to find records in a table
that fit a certain criteria, then copy one field from the record to a text
box. It should then move to the next record that fits the criteria and copy
it to the next text box.
Any ideas on where I am going wrong. It is currently finding the first
record and and puting that field into every text box.
Thanks,
Private Sub SL3()
Dim db As Database
Dim rst As DAO.Recordset
Dim FldNm As String
Dim Box As String
Dim strValue As String
Dim x As Integer
Set db = CurrentDb()
Set rst = db.OpenRecordset("SL3NSNDetail", dbOpenDynaset)
' FldNm = "Nomen"
Box = "txtSL3Item"
x = 0
With rst
If Not (.EOF And .BOF) Then
rst.MoveFirst
Do Until rst.EOF
For x = 1 To 3
' strValue = "Select SL3NSNDetail.[NOMEN] FROM SL3NSNDetail" & _
' "WHERE SL3NSNDetail.[ID] = '" & Forms![IssueForm]![cboWpnType1] & "'"
strValue = _
DLookup("SL3NSNDetail.[NOMEN]", "SL3NSNDetail", "[ID] = '" &
Forms![IssueForm]![cboWpnType1] & "'")
Me.Controls(Box & x).Value = strValue
rst.MoveNext
Next
Loop
End If
End With
rst.Close
Set rst = Nothing
Set db = Nothing
End Sub