Results 1 to 9 of 9
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    If Me. NewRecord or If (Form.NewRecord) (Difference Between)?


    Hi all,
    What is the difference between:
    If Me.NewRecord Then
    If (Form.NewRecord) Then

    Thanks
    Dave

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,957
    No idea. I have always used Me.
    At least that then definitely refers to the form the code is running in?

    From this link it appears that you can test for another form, not just the one the code is running in?
    https://learn.microsoft.com/en-us/of...form.newrecord
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,942
    As far as I can see, nothing in VBA. However, I have never seen Form used.

    Form can be used in a textbox expression.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Thanks all,
    I think Davegri uses it or I beleive thats where I got that code at? I couldnt see it making a difference but have used both
    and never knew if there was a difference. Now I know!
    Thank you again
    Dave

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,942
    Okay, Form can be used to declare object variable as a Form type. Then code passes the form object, not form name.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,414
    I think Davegri uses it or I beleive thats where I got that code at?
    I don't recall ever using that construct, but then, I've have authored a lot of advisory code here at the website that I've never looked at a second time. I probably would remember if I had used in in one of my longer term projects requiring maintenance.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I passed the question to ChatGPT

    In Microsoft Access VBA, both `Me.NewRecord` and `(Form.NewRecord)` are used to determine if the current record being viewed or edited in a form is a new record. However, there's a slight difference in their usage:

    1. `Me.NewRecord`: This is typically used within the code of the form itself. The `Me` keyword refers to the current instance of the form. So `Me.NewRecord` checks if the current form is in a new record state. This is useful when you're writing code within the form module and want to perform certain actions specifically when the form is in the process of creating a new record.

    Example:
    ```vba
    If Me.NewRecord Then
    ' Perform actions specific to a new record
    Else
    ' Perform actions for existing record
    End If
    ```

    2. `(Form.NewRecord)`: This syntax is used when referring to the form from outside its module, such as from another module or a macro. It's used to access the `NewRecord` property of a specific instance of a form. So `(Form.NewRecord)` checks whether a particular instance of a form is in a new record state.

    Example:
    ```vba
    If (Forms!YourFormName.NewRecord) Then
    ' Perform actions specific to a new record
    Else
    ' Perform actions for existing record
    End If
    ```

    In summary, the primary difference lies in the context of usage: `Me.NewRecord` is used within the form's module, while `(Form.NewRecord)` is used outside the form's module to refer to a specific instance of the form. Both serve the same purpose of checking if the current record is new or not.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,942
    ChaptGPT gives partial answer.


    If (Form.NewRecord) Then

    If (Forms!YourFormName.NewRecord) Then

    Sub MySub(frm As Form)
    If frm.NewRecord Then


    The first is synonymous with Me.NewRecord. The other two can be outside form module.

    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Thank you all,
    That was useful information!
    Appriciate it
    Dave

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

Similar Threads

  1. Trying to understand NewRecord
    By GraeagleBill in forum Forms
    Replies: 18
    Last Post: 03-16-2019, 04:55 PM
  2. Replies: 8
    Last Post: 07-02-2018, 07:44 AM
  3. Open Form in Dialog mode in Add NewRecord
    By JrMontgom in forum Programming
    Replies: 1
    Last Post: 02-08-2015, 06:47 PM
  4. Replies: 0
    Last Post: 02-02-2011, 11:08 AM
  5. NewRecord?
    By mwabbe in forum Access
    Replies: 17
    Last Post: 09-20-2010, 01:41 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