I am trying to create a VBA code that allows me to display data from a SQL database.
I'm using this code:
Private Sub Form_Open(Cancel As Integer)
Dim i As Integer
Dim rsPDM As ADODB.Recordset
Dim strPDM As StringSet
rsPDM = New ADODB.Recordset
strPDM = "select * From PDM Where Ugf = 'Centro Litural';"
rsPDM.Open strPDM, CurrentProject.Connection,adOpenDynamic, adLockOptimistici = 1
Do While Not rsPDM.EOF
If i = DLookup("ID", "PDM", "ID =" & i) Then
Me.ID = rsPDM!ID
rsPDM.MoveNext
End If
i = i + 1
Loop
rsPDM.CloseSet
rsPDM = Nothing
End Sub
The code works for a single recordeset.
For many records presents only the latest.
I'm using this code:
Private Sub Form_Open(Cancel As Integer)
Dim i As Integer
Dim rsPDM As ADODB.Recordset
Dim strPDM As StringSet
rsPDM = New ADODB.Recordset
strPDM = "select * From PDM Where Ugf = 'Centro Litural';"
rsPDM.Open strPDM, CurrentProject.Connection,adOpenDynamic, adLockOptimistici = 1
Do While Not rsPDM.EOF
If i = DLookup("ID", "PDM", "ID =" & i) Then
Me.ID = rsPDM!ID
rsPDM.MoveNext
End If
i = i + 1
Loop
rsPDM.CloseSet
rsPDM = Nothing
End Sub
The code works for a single recordeset.
For many records presents only the latest.