I have multiple forms that all do the same thing and I am trying to use one one unbound form with unbound controls instead. The form is set to a continuous form. The unbound form has 3 unbound fields.
The below code works but I only get the last record. I have tried several iterations, but I either get the first record or the last. I am trying to get the first form to work and then will adapt to all the forms.
Any suggestions would be appreciated.
You don't know what you don't know...
The below code works but I only get the last record. I have tried several iterations, but I either get the first record or the last. I am trying to get the first form to work and then will adapt to all the forms.
Any suggestions would be appreciated.
Code:
Private Sub Form_Load()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strUsort As String
Dim ctl As Control
If Len(Me.OpenArgs) > 0 Then
' Position of the pipe
intPos = InStr(Me.OpenArgs, "|")
If intPos > 0 Then
' Retrieve Control Name from the first part of the string
strSQL = Left$(Me.OpenArgs, intPos - 1)
' Retrieve Value to Assign from the end of the string
strUsort = Mid$(Me.OpenArgs, intPos + 1)
End If
Set db = CurrentDb
For Each ctl In Me.Controls
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveFirst
Do While Not rs.EOF
If ctl.Name = "intRecordID" Then
ctl = rs!pk_DomainID
ctl.Visible = True
End If
If ctl.Name = "intStepNumber" Then
ctl = rs!DomainSort
ctl.Visible = True
End If
If ctl.Name = "txtDescription" Then
ctl = rs!DomainDescription
ctl.Visible = True
End If
rs.MoveNext
Loop
rs.Close
Next ctl
End If
'Cleanup
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
You don't know what you don't know...