Results 1 to 5 of 5
  1. #1
    pg13Reader is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    13

    Code not working with tab control


    Hi there!
    I have several forms and want to capture some data as an audit trail of when a change was made to a record. The following works in one of my forms:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Me.DateEdited = Now()
    End Sub

    Very simple and works beautifully.

    But the form where I have an tab control it doesn’t work. I tried using a reference to the table, such as: Me.t_Clients.DateEdited = Now()
    and get the following Visual Basic error:
    Compile error – method or data member not found.

    Compiling gives me the same error.
    Does anyone know what am I doing wrong?
    Thank you!!

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Tab controls have no bearing on referencing items on them UNLESS you have a subform on the tab control and then it is only the subform control (control on the parent form which houses the subform) you have to worry about.

    If you aren't using a subform, then the reference would be the same. If you ARE using a subform then you would need to reference the control like:

    Me.SubformControlNameHere.Form.DateEdited = Now()

    where SubformControlNameHere is the name of the actual subform control on the main form which houses the subform on it, and not the name of the subform itself UNLESS the subform control and the subform share the exact same name. The .Form. part is necessary to tell Access you want to refer to something on the subform and not the subform control.

  3. #3
    pg13Reader is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    13
    Hi Bob, Thanks for the suggestion, but it's the main form that has the fields I'm trying to update. I made a copy of the form and removed the tab control, thinking I was back to the basics with the form, but it's still giving me the same error. There is a combo box, pulling data from another table that also has the same field name (prefer not the have different names here). Adding the reference to the specific table/field doesn't seem to work. Any other ideas?
    Many thanks!

  4. #4
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Make sure that the control name and the field name (that the control is bound to) are not the same. Then refer to the control name.

  5. #5
    pg13Reader is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    13
    That was the trick! I didn't have those fields on the form, but since this works I'll use it. They can be hidden, right?
    Thank you very much!! I was pulling out lots of hair on this one.

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. DLookup code not working
    By lukekelly in forum Programming
    Replies: 9
    Last Post: 06-15-2010, 06:08 AM
  4. VB code not working
    By cwwaicw311 in forum Programming
    Replies: 17
    Last Post: 04-26-2010, 07:02 PM
  5. VBA Code for working with IE
    By smikkelsen in forum Programming
    Replies: 3
    Last Post: 04-15-2010, 01:05 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