W dniu 03.10.2020 o 20:25, Stan pisze:
Ale co Ty rozumiesz przez pojęcie pierwszy rekord. Tak naprawdę Access
nie rozróżnia pojęcia pierwszy rekord dla zestawu nieposortowanych
rekordów.
Z pomocy MS Access:
You can use the DFirst function to return a RANDOM record from a
^^^^^^^^^^^^^^^^^^^^^^^^^^
particular field in a table or query when you simply need any value from
that field.
Note
If you want to return the first or last record in a set of records (a
domain (domain: A set of records that is defined by a table, a query, or
an SQL expression. Domain aggregate functions return statistical
information about a specific domain or set of records.)), you should
create a query sorted as either ascending or descending and set the
TopValues property to 1.
From Visual Basic, you can also create an ADO Recordset object and use
the MoveFirst or MoveLast method to return the first or last record in a
set of records.
Nie mniej jednak masz przykładowy kod, jak to zrobić:
'________________________________
Private Sub btnUpdate_Click()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim sSQL As String
' czy wszystko wpisane
If Len(Nz(Me!PoleKombi1, "")) = 0 Or _
Len(Nz(Me!Data, "")) = 0 Or _
Len(Nz(Me!Liczba, "")) = 0 Then
MsgBox "Niepełne dane!"
Exit Sub
End If
sSQL = "SELECT Pole2, Pole3 FROM Tabela1 WHERE " & _
"(Pole2 Is Null) AND " & _
"(Pole3 Is Null) AND " & _
"Pole1=" & Me!PoleKombi1 & ";"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(sSQL, dbOpenDynaset)
With rst
If .EOF Or .BOF Then
MsgBox "Brak rekordu!"
Else
.MoveFirst
.Edit
!Pole2 = Me!Data
!Pole3 = Me!Liczba
.Update
End If
End With
rst.Close
Set rst = Nothing
Set dbs = Nothing
End Sub
--
Pozdrawiam
Zbigniew Bratko