Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Before Update event (Access 2000)

    BeforeUpdate event

    I refer to my question about the dates being not displayed in a report and i received the answer from Hans. As always he is right, the reason is that the fields afid and lastupdate are not populated. In order to do that, i have put in the BeforeUpdate event the following code:

    Me.LastUpdated = Now
    If IsOpen(strDocName) = True Then
    Me![afid].DefaultValue = Forms![FBenchmark]![Office]
    DoCmd.RunCommand acCmdSaveRecord
    End If

    I have put this code in both the main form and the subform, just to be sure,but nevertheless the fields are not populated.
    What may be the reason?

    I am sending the same db, with the forms added.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Before Update event (Access 2000)

    You use a variable strDocName that has not been declared and has not been given a value. And you use a function IsOpen that is not defined within the database. So the code in the database as posted will never work.

  3. #3
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Before Update event (Access 2000)

    In addition to Hans' comments, your code is running on the BeforeUpdate event of the control LastUpdated, not the BeforeUpdate event of the Form. Unless someone actually puts data in the control, it will never fire the event. Move your code to the Form event and see if that does what you want.
    Wendell

  4. #4
    3 Star Lounger
    Join Date
    Jul 2001
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Before Update event (Access 2000)

    Edited by HansV to remove superfluous line ends. There is no need to press Enter every few words. The browser will break the lines automatically.

    Why my code doesnt work? I will be grateful for your help.I have declared the strDoc ariable,i have defined the IsOpen function within the database, and i have put the code in the code, as Mr Wendel has advices me,but as you could see in the applied database,,the afid field remains blank, and it should be 7 in my case.

    <hr>You use a variable strDocName that has not been declared and has not been given a value. And you use a function IsOpen that is not defined within the database. So the code in the database as posted will never work.<hr>

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Before Update event (Access 2000)

    Look at your code (I have indented it for readability):
    <pre>Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim StrDocName As String
    Me.LastUpdated = Now
    If IsOpen(StrDocName) = True Then
    Me![afid].DefaultValue = Forms![FBenchmark]![Office]
    DoCmd.RunCommand acCmdSaveRecord
    End If
    End Sub
    </pre>

    You have declared StrDocName, but you don't assign it a value (I mentioned this in my first reply). So when you test IsOpen(StrDocName), the variable StrDocName is empty. You must give StrDocName a value:
    <pre> StrDocName = "FBenchmark"
    </pre>

    below the line <code>Dim StrDocName As String</code>. However, I don't think it will do what you want. The code will set the default value for afid in new records. It will not change the value of afid in the record being updated. And it will not fill in afid in already existing records either. You will have to fill in the afid in existing records manually, or using an update query. I'm not sure what to recommend for new records, since I don't understand why you have a main form and subform.

  6. #6
    3 Star Lounger
    Join Date
    Jul 2001
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Before Update event (Access 2000)

    i will study your reply carefully and follow your advices, but i want to thank you indeed for the considerate and detailed reply you have given to me

    kind regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •