Public Sub

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I have various input forms for users to enter data. When the form opens I
wish to warn them of about the form adding records. To this end I have
created a public sub

Public Sub AddRecordsub()

Dim Message, Title, MyValue
Message = "Entering This Form Will Add Records. Are You Sure This Is What
You Want To Do" ' Set prompt.
Title = "Add Record Message" ' Set title.
' Display message, title.
retValue = MsgBox(Message, Title, vbYesNo)
If retValue = vbYes Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
End If
End Sub

Within the main start form I have a command button to open the input data
form with the code below

Private Sub cmdnewassitclient_Click()
On Error GoTo Err_cmdnewassitclient_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmassistcliententry"
AddRecordsub

Exit_cmdnewassitclient_Click:
Exit Sub

Err_cmdnewassitclient_Click:
MsgBox Err.description
Resume Exit_cmdnewassitclient_Click

End Sub

The problem I am having is when the Public sub is called I am getting an
error saying Function or Sub is not defined.

Any ideas where I am going wrong and also am I heading in the right
direction with my code as this is only the second Public Sub/Function I have
created

Thanks

Richard
 
Is the public sub saved in a standard module? (as opposed to in a form's
class module)

HTH
 
In
richard said:
Hi
I have various input forms for users to enter data. When the form
opens I wish to warn them of about the form adding records. To this
end I have created a public sub

Public Sub AddRecordsub()

Dim Message, Title, MyValue
Message = "Entering This Form Will Add Records. Are You Sure This Is
What You Want To Do" ' Set prompt.
Title = "Add Record Message" ' Set title.
' Display message, title.
retValue = MsgBox(Message, Title, vbYesNo)
If retValue = vbYes Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
End If
End Sub

Within the main start form I have a command button to open the input
data form with the code below

Private Sub cmdnewassitclient_Click()
On Error GoTo Err_cmdnewassitclient_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmassistcliententry"
AddRecordsub

Exit_cmdnewassitclient_Click:
Exit Sub

Err_cmdnewassitclient_Click:
MsgBox Err.description
Resume Exit_cmdnewassitclient_Click

End Sub

The problem I am having is when the Public sub is called I am getting
an error saying Function or Sub is not defined.

Any ideas where I am going wrong and also am I heading in the right
direction with my code as this is only the second Public Sub/Function
I have created

Thanks

Richard

First, where -- in what module -- is your AddRecordsub defined? For
your purposes, it ought to be in a standard module, not in a form
module.

Second, you're not passing the name of the form or the link criteria to
AddRecordsub, so there's no connection between the "stDocName" and
"stLinkCriteria" used in that procedure to the ones defined in your
calling routine. Change the Sub's definition to:

Public Sub AddRecordsub( _
stDocName As String, _
Optional stLinkCriteria As String)

Then pass those values when calling the sub:

AddRecordsub stDocName, stLinkCriteria

or, since the above definition makes stLinkCriteria optional, you can
just write

AddRecordsub stDocName

or

AddRecordsub "frmassistcliententry"
 

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


Back
Top