Avatar billede mss Nybegynder
24. august 2000 - 11:57 Der er 1 kommentar og
1 løsning

Brug af VB til at undersøge, om en post er ændret i Access

Jeg har brug for en kommando i VB der undersøger om en eksisterende post er blevet ændret, men skal ikke reagere, hvis der er tale om en ny post, som oprettes.

Kommandoen indtastets i Form_beforeupdate

Formålet hermed er at give brugeren en mulighedhed for at \"undo\" ved brug af kommandoen (me.undo) og en \"msgbox\".






Avatar billede mss Nybegynder
24. august 2000 - 12:05 #1
Er løst således:

ACC2000: How to Prompt User to Save Changes to Record in a Form

--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Access 2000

--------------------------------------------------------------------------------
Moderate: Requires basic macro, coding, and interoperability skills.



SUMMARY
When you move to the next record on a form or close a form, Microsoft Access automatically saves any changes that you have made to the current record. This article shows you how to use a BeforeUpdate event procedure to prompt you to verify the save operation before Microsoft Access will continue.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:



http://mcspreferral.microsoft.com/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:


http://support.microsoft.com/directory/overview.asp



MORE INFORMATION
CAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.

This example uses the BeforeUpdate event procedure in the Customers form to prompt the user to confirm changes before Microsoft Access will save the record:

Open the sample database Northwind.mdb, and open the Customers form in Design view.


Set the form\'s BeforeUpdate property to the following event procedure:


Private Sub Form_BeforeUpdate(Cancel As Integer)

  \' This procedure checks to see if the data on the form has
  \' changed. If the data has changed, the procedure prompts the
  \' user to continue with the save operation or to cancel it. Then
  \' the action that triggered the BeforeUpdate event is completed.

  Dim ctl As Control

  On Error GoTo Err_BeforeUpdate

  \' The Dirty property is True if the record has been changed.
  If Me.Dirty Then
      \' Prompt to confirm the save operation.
      If MsgBox(\"Do you want to save?\", vbYesNo + vbQuestion, _
              \"Save Record\") = vbNo Then
        Me.Undo
      End If
  End If

Exit_BeforeUpdate:
  Exit Sub

Err_BeforeUpdate:
  MsgBox Err.Number & \" \" & Err.Description
  Resume Exit_BeforeUpdate
End Sub
On the Debug menu, click Compile Northwind.


On the File menu, click Save Northwind.


On the File menu, click Close And Return to Microsoft Access.


Now, when you make a change to a record, and then you either move to a different record or close the form, you are prompted to confirm that you want to save the current record. If you click No, the record is reset and the operation continues as normal. 
Avatar billede sjensen Nybegynder
24. august 2000 - 12:08 #2
Jeg tror ikke på at der findes en simpel kommando til deette formål, hverken i Access eller i VB.

Principperne bag dette behov er at man gemmer en kopi af den oprindelige record i memory når man læser den ind. Ved ændring af recorden gemmer man ligeledes ændringerne i felter i memory, og lige før recorden skal opdateres, læser man den ind igen of checker om den er blevet ændret op mod den oprindelige man læste ind. Hvis ikke kan man gemme de ændringer man har lavet, og hvis den er ændret i mellemtiden er det så op til dig hvad der skal ske.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester