Call function from a form

G

Guest

I have a public function in a form: Public Function DeleteNewRecord()

I'm trying to call that function from another form and I keep getting the
error message: "There is an invalid use of ! or .(dot) or invalid parenthesis.

Private Sub CancelNewRecord_Click()
DoCmd.Close
DoCmd.OpenForm "NewPartInputfrm", , , , acFormEdit
DoCmd.GoToRecord , , acLast
Forms![NewPartInputfrm]![Model#] = "test"
Call Forms.NewPartInputfrm.DeleteNewRecord

End Sub

Am I calling this wrong? I don't want to put the DeleteNewRecord() in a
module because I'm using a lot of Me.field name and I don't want to include
the form name to the code because it's quite long. Thank you.
 
N

Nick 'The database Guy'

Hi Alex,

Surely you have it the wrong way around, shouldn't it be:

Call DeleteNewRecord(Forms.NewPartInputfrm)

Good luck
 
G

Guest

Move the function to a standard module. A Public function can be called from
anywhere in your app.
 
M

Marshall Barton

Alex said:
I have a public function in a form: Public Function DeleteNewRecord()

I'm trying to call that function from another form and I keep getting the
error message: "There is an invalid use of ! or .(dot) or invalid parenthesis.

Private Sub CancelNewRecord_Click()
DoCmd.Close
DoCmd.OpenForm "NewPartInputfrm", , , , acFormEdit
DoCmd.GoToRecord , , acLast
Forms![NewPartInputfrm]![Model#] = "test"
Call Forms.NewPartInputfrm.DeleteNewRecord

End Sub

Am I calling this wrong? I don't want to put the DeleteNewRecord() in a
module because I'm using a lot of Me.field name and I don't want to include
the form name to the code because it's quite long. Thank you.


I don't understand the closing and opening forms here, but
the function call needs to be:

Call Forms!NewPartInputfrm.DeleteNewRecord
 
G

Guest

Get a "syntax error" when using typing:

Call Forms!NewPartInputfrm.CreateDuplicateRecord.

Get "item not found in collection" when using:

Call Forms.NewPartInputfrm.CreateDuplicateRecord

My function is: Public Function CreateDuplicateRecord()

With Me.RecordsetClone
.AddNew
!Model = [Forms]![CreateDuplicateRecord]![ChooseModel]
!NHL = [Forms]![CreateDuplicateRecord]![NewNHL]
![Part#] = Me.[Part#]
!PartName = Me.PartName
!Qty = Me.Qty
![Make/Buy] = Me.[Make/Buy]
!Status = Me.Status
'. . .
.Update
' make new record current
Me.Bookmark = .LastModified
End With

End Function

If I put it in a module, how does it know what form Me. is referring to?


Marshall Barton said:
Alex said:
I have a public function in a form: Public Function DeleteNewRecord()

I'm trying to call that function from another form and I keep getting the
error message: "There is an invalid use of ! or .(dot) or invalid parenthesis.

Private Sub CancelNewRecord_Click()
DoCmd.Close
DoCmd.OpenForm "NewPartInputfrm", , , , acFormEdit
DoCmd.GoToRecord , , acLast
Forms![NewPartInputfrm]![Model#] = "test"
Call Forms.NewPartInputfrm.DeleteNewRecord

End Sub

Am I calling this wrong? I don't want to put the DeleteNewRecord() in a
module because I'm using a lot of Me.field name and I don't want to include
the form name to the code because it's quite long. Thank you.


I don't understand the closing and opening forms here, but
the function call needs to be:

Call Forms!NewPartInputfrm.DeleteNewRecord
 
M

Marshall Barton

The Item not found message implies that form NewPartInputfrm
is not open. The Forms collection only includes open forms.
--
Marsh
MVP [MS Access]

Get a "syntax error" when using typing:

Call Forms!NewPartInputfrm.CreateDuplicateRecord.

Get "item not found in collection" when using:

Call Forms.NewPartInputfrm.CreateDuplicateRecord

My function is: Public Function CreateDuplicateRecord()

With Me.RecordsetClone
.AddNew
!Model = [Forms]![CreateDuplicateRecord]![ChooseModel]
!NHL = [Forms]![CreateDuplicateRecord]![NewNHL]
![Part#] = Me.[Part#]
!PartName = Me.PartName
!Qty = Me.Qty
![Make/Buy] = Me.[Make/Buy]
!Status = Me.Status
'. . .
.Update
' make new record current
Me.Bookmark = .LastModified
End With

End Function

If I put it in a module, how does it know what form Me. is referring to?


Marshall Barton said:
Alex said:
I have a public function in a form: Public Function DeleteNewRecord()

I'm trying to call that function from another form and I keep getting the
error message: "There is an invalid use of ! or .(dot) or invalid parenthesis.

Private Sub CancelNewRecord_Click()
DoCmd.Close
DoCmd.OpenForm "NewPartInputfrm", , , , acFormEdit
DoCmd.GoToRecord , , acLast
Forms![NewPartInputfrm]![Model#] = "test"
Call Forms.NewPartInputfrm.DeleteNewRecord

End Sub

Am I calling this wrong? I don't want to put the DeleteNewRecord() in a
module because I'm using a lot of Me.field name and I don't want to include
the form name to the code because it's quite long. Thank you.


I don't understand the closing and opening forms here, but
the function call needs to be:

Call Forms!NewPartInputfrm.DeleteNewRecord
 
N

Nick 'The database Guy'

If you put it a module, the code will not know what 'me' refers to, so
don't use 'me'. Refer to the form implicitly using the syntax
'Forms!frmMyForm'

Good luck,

Nick said:
Get a "syntax error" when using typing:

Call Forms!NewPartInputfrm.CreateDuplicateRecord.

Get "item not found in collection" when using:

Call Forms.NewPartInputfrm.CreateDuplicateRecord

My function is: Public Function CreateDuplicateRecord()

With Me.RecordsetClone
.AddNew
!Model = [Forms]![CreateDuplicateRecord]![ChooseModel]
!NHL = [Forms]![CreateDuplicateRecord]![NewNHL]
![Part#] = Me.[Part#]
!PartName = Me.PartName
!Qty = Me.Qty
![Make/Buy] = Me.[Make/Buy]
!Status = Me.Status
'. . .
.Update
' make new record current
Me.Bookmark = .LastModified
End With

End Function

If I put it in a module, how does it know what form Me. is referring to?


Marshall Barton said:
Alex said:
I have a public function in a form: Public Function DeleteNewRecord()

I'm trying to call that function from another form and I keep getting the
error message: "There is an invalid use of ! or .(dot) or invalid parenthesis.

Private Sub CancelNewRecord_Click()
DoCmd.Close
DoCmd.OpenForm "NewPartInputfrm", , , , acFormEdit
DoCmd.GoToRecord , , acLast
Forms![NewPartInputfrm]![Model#] = "test"
Call Forms.NewPartInputfrm.DeleteNewRecord

End Sub

Am I calling this wrong? I don't want to put the DeleteNewRecord() in a
module because I'm using a lot of Me.field name and I don't want to include
the form name to the code because it's quite long. Thank you.


I don't understand the closing and opening forms here, but
the function call needs to be:

Call Forms!NewPartInputfrm.DeleteNewRecord
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Run Code 3
Public Sub Help 3
bug in form event code 4
Function call 13
populate form with a recordset 3
Help Linking Subform and Form 2
Function Call ? 8
Running a Subform Function from a Main Form 3

Top