Hi all,
What is the difference between:
If Me.NewRecord Then
If (Form.NewRecord) Then
Thanks
Dave
Hi all,
What is the difference between:
If Me.NewRecord Then
If (Form.NewRecord) Then
Thanks
Dave
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
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.
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
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.
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.I think Davegri uses it or I beleive thats where I got that code at?
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.
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.
Thank you all,
That was useful information!
Appriciate it
Dave