🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.bazy-danych.msaccess
Article #137717

Re: Pierwszy wolny rekord, edycja

#137717
From: Zbigniew Bratko
Date: Sun, 04 Oct 2020 10:25
82 lines
3887 bytes
W dniu 03.10.2020 o 20:25, Stan pisze:
> Witam zacne grono ekspertów.
> Mam Tabelę1, w której Pole1 (liczba) ma w kilku rekordach tą samą wartość (na przykład 13).
> 
> Formularz1 ma PoleKombi1 i pola niezwiązane "Data" i "Liczba"
> Po wybraniu z PolaKombi1 wartości "13", wypełnieniu pól niezwiązanych i naciśnięciu Buttona marzy mi się coś w rodzaju:
> 
> CurrentDb.Execute "UPDATE Tabela1 SET (Pole2, Pole3) SELECT " ' & Me!Data & " ', ' " & Me!Liczba & " ' "
> - i tu chciałbym dodać warunek, że aktualizowany ma być Pierwszy rekord z wartością Pola1="13", w którym Pola2 i Pole3 są puste.
> 
> Uprzejmie proszę o próbę pomocy :)
> Stan
> 

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
Technical Details
Message-ID: <5f79a343$0$553$65785112@news.neostrada.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!goblin2!goblin.stu.neva.ru!aioe.org!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
References: <7f747a0f-4b7a-417b-a6f5-a9e566ab6442n@googlegroups.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!goblin2!goblin.stu.neva.ru!aioe.org!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
Subject: Re: Pierwszy wolny rekord, edycja
Newsgroups: pl.comp.bazy-danych.msaccess
References: <7f747a0f-4b7a-417b-a6f5-a9e566ab6442n@googlegroups.com>
From: Zbigniew Bratko <adminBEZTEGO@accdb.pl>
Date: Sun, 4 Oct 2020 12:25:54 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1
MIME-Version: 1.0
In-Reply-To: <7f747a0f-4b7a-417b-a6f5-a9e566ab6442n@googlegroups.com>
Lines: 108
Message-ID: <5f79a343$0$553$65785112@news.neostrada.pl>
Organization: Telekomunikacja Polska
NNTP-Posting-Host: 37.248.157.113
X-Trace: 1601807171 unt-rea-a-02.news.neostrada.pl 553 37.248.157.113:22022
X-Complaints-To: abuse@news.neostrada.pl
X-Received-Bytes: 4319
X-Received-Body-CRC: 1271194493
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit