Results 1 to 8 of 8
  1. #1
    wnuczus is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Mar 2017
    Posts
    5

    Problem with edit form via VBA

    Hi have ID Pesel



    Code:
    Option Compare Database
    
    Private Sub WIEK_Click()
    
    
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        
        Set db = CurrentDb
        Set rs = db.OpenRecordset("Klienci")
    
    
    
    
    Dim dzien
    Dim miesiac
    Dim rok
    Dim Datowanie
    Dim Wiekowanie
    
    
    rok = 1900 + (Mid(PESEL, 1, 2))
    miesiac = Mid(PESEL, 3, 2)
    dzien = Mid(PESEL, 5, 2)
    
    
    Datowanie = DateSerial(rok, miesiac, dzien)
    Wiekowanie = DateDiff("yyyy", Datowanie, Date)
    
    
        rs.Edit
        rs!WIEK = Wiekowanie
        rs.Update
        
    'MsgBox (Wiekowanie)
    
    
    
    
    End Sub
    and my script in VBA set age form PESEL but alway my script only change first form and I want only set in current record how can I do it?

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You haven't moved on to the specific record you wish to update.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    You don't need vb code to do this.
    this can be done in a form or a query ,without vb code.

  4. #4
    wnuczus is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Mar 2017
    Posts
    5
    Quote Originally Posted by aytee111 View Post
    You haven't moved on to the specific record you wish to update.
    Ok, but how can I do it? I am new in VBA I can create own function script but I have problem with including to form

  5. #5
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Did you try doing it in a query, without the VBA?

    To move to a specific record : rs.FindFirst primarykeyfield=...

  6. #6
    wnuczus is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Mar 2017
    Posts
    5
    Ok maybe I am stupid but where can I put code sql in form? I want use form

  7. #7
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    First, create a query the way you want it and get it working. Use the field on the form as your criteria (=Forms!formname!formfieldname). Then copy the SQL to VBA, remove all the code you have and replace with DoCmd.Runsql "...paste SQL here...". Change the criteria to say =" & me!formfieldname & "

  8. #8
    wnuczus is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Mar 2017
    Posts
    5
    Ok I found solution I used me.Wiekowanie now works perfectly!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 21
    Last Post: 08-05-2013, 06:23 AM
  2. Cannot Edit Form
    By Derrick T. Davidson in forum Queries
    Replies: 7
    Last Post: 06-16-2013, 07:26 AM
  3. Replies: 1
    Last Post: 05-31-2013, 08:53 AM
  4. Next Problem: Edit Previous updates
    By Moridan in forum Access
    Replies: 4
    Last Post: 05-07-2013, 01:54 PM
  5. Replies: 1
    Last Post: 12-04-2011, 09:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums