Results 1 to 8 of 8
  1. #1
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162

    Could someone explain why this code isnt working please?


    As the title suggests, I had a go at writing some VBA but all I get is errors. Obviously Im oding something wrong but Google wont help me out so I was wondering if someone here could please?

    Code:
    Private Sub DeleteRecord_Click()
    If Me.TimesheetTableSubform.Form = "" Then
    MsgBox "You have no records to delete"
    Else
    Me.TimesheetTableSubform.Form.Recordset.Delete
    Me.TimesheetTableSubform.Form.Recordset.MoveNext
    End Sub
    Thanks

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    What exactly are you trying to do?
    Can you post an mdb version of your database -- remove anything confidential?

    I have Acc2003 so can't open 2007 or 2010 accdb.

    I think you need to check the recordcount along these lines

    Me.TimesheetTableSubform.Form.Recordset.RecordCoun t

  3. #3
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    Im trying to check if the subform has any entries before it attempts to delete a row from the subform. I think Im making a bit of a lash up on this cant attach 2003 version as Im using 2007 functions.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    You could try putting a debug statement into your code and step through it.

    Debug.print Me.TimesheetTableSubform.Form.Recordset.RecordCoun t

    Put this line a first line in your DeleteRecord_Click proc

    Make this a breakpoint
    Run your procedure, use F8 to step thru and see what the count is.

  5. #5
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    I get a compile error block if without end if :S

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Post the procedure code.

  7. #7
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    I think I get it but I dont know what needs to go in place

    Code:
    Private Sub DeleteRecord_Click()
    If Me.TimesheetTableSubform.Form.Recordset = "" Then
    MsgBox "You have no records to delete"
    Else if Me.TimesheetTableSubform.'here
    Me.TimesheetTableSubform.Form.Recordset.Delete
    Me.TimesheetTableSubform.Form.Recordset.MoveNext
    End Sub
    'here (This is where I think I need to tell it that if there is something there then....) But I dont know what needs to go there

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Private Sub DeleteRecord_Click()
    Debug.print Me.TimesheetTableSubform.Form.Recordset.RecordCoun t
    If Me.TimesheetTableSubform.Form = "" Then
    MsgBox "You have no records to delete"
    Else
    Me.TimesheetTableSubform.Form.Recordset.Delete
    Me.TimesheetTableSubform.Form.Recordset.MoveNext
    End Sub


    For some reason, the editor is sticking a blank before the final t in RecordCount. There should be no space before the t.

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

Similar Threads

  1. VBA Code not working how it Should
    By Juan4412 in forum Programming
    Replies: 7
    Last Post: 12-07-2010, 01:59 PM
  2. VBA Code Not working
    By jo15765 in forum Programming
    Replies: 12
    Last Post: 12-03-2010, 04:01 PM
  3. VB code not working
    By cwwaicw311 in forum Programming
    Replies: 17
    Last Post: 04-26-2010, 07:02 PM
  4. VBA Code for working with IE
    By smikkelsen in forum Programming
    Replies: 3
    Last Post: 04-15-2010, 01:05 AM
  5. Could someone please explain to me what a Switchboard is
    By wabbalee in forum Database Design
    Replies: 2
    Last Post: 06-26-2009, 07:20 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