Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sub or function not defined

Status
Not open for further replies.
Jan 14, 2002
143
0
0
US
Can't I place a public procedure behind a FORM and call it from anywhere in the application? Could someone help me understand why I'm getting the error "sub or function not defined" when I try to call it from a subform.

Thanks


This is what's in the main form that I want to call from the subform:

Public Sub RequeryChangeOrderTotals()
On Error GoTo ErrorHandler

Dim db As Database
Dim Job As String
Dim Subm As String
Dim Unsubm As String
Dim ContingUnsubm As String
Dim ContingSubm As String
Dim sqlSubmitted As String
Dim sqlUnsubmitted As String
Dim rstSubmitted As Recordset
Dim rstUnsubmitted As Recordset

Job = Forms!frmChangeOrders_Module!JobID
Subm = "Forms!frmChangeOrders_Module!frmChangeOrders_Tabs!txtSubmittedTotal"
Unsubm = "Forms!frmChangeOrders_Module!frmChangeOrders_Tabs!txtUnsubmittedTotal"
ContingUnsubm = "Forms!frmChangeOrders_Module!frmChangeOrders_Tabs.form!txtSubmittedTotal"
ContingSubm = "Forms!frmChangeOrders_Module!frmChangeOrders_Tabs.form!txtUnsubmittedTotal"

sqlSubmitted = "SELECT COAmount FROM qryChangeOrders_Listbox_SubmittedChangeOrdersLog WHERE JobID='" & Job & "'"
sqlUnsubmitted = "SELECT COAmount FROM qryChangeOrders_Listbox_UnsubmittedChangeOrdersLog WHERE JobID='" & Job & "'"

If Not IsNull(Forms!frmChangeOrders_Module!JobID) Then
Set db = CurrentDb
Set rstSubmitted = db.OpenRecordset(sqlSubmitted, dbOpenForwardOnly)
Set rstUnsubmitted = db.OpenRecordset(sqlUnsubmitted, dbOpenForwardOnly)
If rstSubmitted.RecordCount <> 0 Then
Subm = rstSubmitted!COAmount
ContingSubm = rstSubmitted!COAmount
End If
If rstUnsubmitted.RecordCount <> 0 Then
Unsubm = rstUnsubmitted!COAmount
ContingUnsubm = rstUnsubmitted!COAmount
End If
rstSubmitted.Close
rstUnsubmitted.Close
db.Close
Set rstSubmitted = Nothing
Set rstUnsubmitted = Nothing
Set db = Nothing
End If

ExitHere:
Exit Sub

ErrorHandler:
rstSubmitted.Close
rstUnsubmitted.Close
db.Close
Set rstSubmitted = Nothing
Set rstUnsubmitted = Nothing
Set db = Nothing
MsgBox &quot;An error occurred: &quot; & Err.Description
Resume ExitHere

End Sub





And then I call it from a subform:

Private Sub Form_AfterUpdate()

RequeryChangeOrderTotals

End Sub

 
You can, but you must remember that a form in an object, therefore, you must identify the object before invoking one of its methods.

Private Sub Form_AfterUpdate()

MainFormName.RequeryChangeOrderTotals

End Sub

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Your other option would be to place your sub procedure in a module. But again make sure tha tany variables are properly qualified.

Thanks and Good Luck!

zemp
 
Ok, that makes sense referencing the form, but I tried it and kept getting error &quot;object required.&quot; Got impatient and resorted to putting it in with the modules...not totally happy about it, but whatever works.

Thanks
 
Where I said MainFormName that should be the actual name of the form, what ever you named it. You can find out the name of the form by looking at the Name property of the form, or in the IDE, setting that name to whatever you prefer.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
CajunCenturion, I'll try not to take your assumption personally - you've probably helped people who have misunderstand that before.

Evidently something else is wrong but I do not have the luxury of time to figure it out. So I'm content putting it in with the modules.

A sincere thanks for your help.

-Blaine




 
I'm sorry JumpinJimRivers, there was certainly nothing personal intended. I'm glad that you were able to find a workable solution.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top