I'm trying to create a VBA code that allows me to display a data of SQL database to a form.
I'm using this code to access and display data:
Private Sub Form_Open(Cancel As Integer)
Dim i As Integer
Dim rsPDM As ADODB.Recordset
Dim strPDM As String
Set rsPDM = New ADODB.Recordset
strPDM = "select * From PDM Where Ugf = 'Centro Litural';"
rsPDM.Open strPDM, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
i = 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.Close
Set rsPDM = Nothing
End Sub
In the form appears in all the camps the last Id of the database.
I'm using this code to access and display data:
Private Sub Form_Open(Cancel As Integer)
Dim i As Integer
Dim rsPDM As ADODB.Recordset
Dim strPDM As String
Set rsPDM = New ADODB.Recordset
strPDM = "select * From PDM Where Ugf = 'Centro Litural';"
rsPDM.Open strPDM, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
i = 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.Close
Set rsPDM = Nothing
End Sub
In the form appears in all the camps the last Id of the database.