Results 1 to 4 of 4
  1. #1
    George R is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2019
    Posts
    2

    Delete record in subform using VBA

    We have an annual event and we want track attendance from yea to year. I'm trying to program a command button on frmMembers to delete an entry on frmAttendSubform. I would appreciate suggestions on correcting the following:
    Private Sub Undo_Click()


    'Remove record for current year from Prior Years table for this person
    Dim myPal As Long
    Dim mySession As Long
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strSQL As String
    myPal = Me.WorkerID
    mySession = CStr(Year(Date))
    Set db = CurrentDb
    strSQL = "SELECT* FROM tblAttendSubform WHERE (WorkerID = " & myPal & ") And (Session = '" & mySession & "')"
    Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    'test for no record selected (i.e. cursor is on the new record line)
    If Not IsNull(Forms!frmAttendSubform!Controls.Session.Val ue) Then
    rs.Delete
    Else
    MsgBox "Current Year has not been entered."
    End If
    rs.Close
    Set rs = Nothing
    Set db = Nothing
    'Uncheck the box
    Me.NTD = False
    End Sub
    The most recent error was 3078 unable to locate

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Please post lengthy code within code tags (# on toolbar) and use indentation. You can always edit a post if you forget.
    Not seeing a need for all that code. Why not just run a delete query that gets the values from your form? You might still need to validate conditions, but other than being on a new record, I can't discern what they might be. IF Me.NewRecord should be enough without opening a recordset, for which by the way, delete is not supported. At least, not any longer.
    Last edited by Micron; 03-16-2019 at 04:24 PM. Reason: clarification and correction
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    George R is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2019
    Posts
    2
    I'm trying the suggestion to use a delete query and am trying thisELETE tblAttendance.AttendID, tblAttendance.WorkerID, tblAttendance.SessionFROM tblAttendance INNER JOIN tblWorkers ON tblAttendance.WorkerID = tblWorkers.WorkerID
    WHERE (((tblAttendance.WorkerID)=[tblWorkers].[WorkerID]) AND ((tblAttendance.Session)=CStr(Year(Now()))));
    I get the error code 3128 "Specify the table for the deletion....
    Would appreciate a suggestion
    Thanks!

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Take a look at my first sentence from my first post. That is my suggestion -

    for not getting smilies in your code and other undesirable effects (tblAttendance.SessionFROM <-- SessionFROM?)

    I'm sorry but I can't help if you're going to ignore basic questions or requests.

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

Similar Threads

  1. Replies: 7
    Last Post: 10-08-2015, 09:14 AM
  2. Replies: 1
    Last Post: 09-16-2014, 02:26 PM
  3. Replies: 1
    Last Post: 10-22-2013, 06:48 AM
  4. Replies: 4
    Last Post: 07-03-2013, 10:02 AM
  5. Delete record from nested subform
    By raton in forum Forms
    Replies: 1
    Last Post: 04-14-2012, 11:39 AM

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