Object Required message appears when running a Function Routine

G

Guest

I'm constructing an Access 2000 database, which calls a VB sub routine, when
a command button is clicked, to open a form, which then calls a converted
Macro function routine to set several field values from the original form.

The function routine does set the specified field values and then stops with
an "Object required" message. Clicking on the OK exits the sub routine
without executing the remaining code of the function routine or the sub
routine from which it was called.

What object is Access / VB looking for ? I've been unable to find anything
in either Access or the VB help files.

I've included the VB code for both the sub routine and the called function
below.

Private Sub Cmd_ArrangeService_Click()
On Error GoTo Err_Cmd_ArrangeService_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Service Work"
DoCmd.OpenForm stDocName, , , stLinkCriteria

'Module Converted Macro-Service Work
RunCode.Function Service_Work()

stDocName = "Customers"
DoCmd.Close acForm, stDocName, acSaveYes

Exit_Cmd_ArrangeService_Click:
Exit Sub

Err_Cmd_ArrangeService_Click:
MsgBox Err.Description
Resume Exit_Cmd_ArrangeService_Click

End Sub
'------------------------------------------------------
'------------------------------------------------------
Function Service_Work()
On Error GoTo Service_Work_Err

With CodeContextObject
Forms!Service_Work!CustomerName = Forms!Customers!CustomerName
Forms!Service_Work!CustomerID = Forms!Customers!CustomerID
Forms!Service_Work!EquipmentID = .EquipmentID
Forms!Service_Work!Equipment = .Equipment
Forms!Service_Work!HeatSource = .HeatSource
Forms!Service_Work!EquipmentSerialNumber = .EquipmentSerialNumber
DoCmd.GoToControl "CustomerContact"
End With

Service_Work_Exit:
Exit Function

Service_Work_Err:
MsgBox Error$
Resume Service_Work_Exit

End Function

Hope someone can help.

Many thanks

Nicholas @ Double D
 
G

Guest

hi,
CodeContextObject
what is this? when did you set this object?
the function does not set anything.
looks like you are trying to tranfer the contents of
contols on the first form to the controls of a second form.
if so you don't need the function. just put the code
between the open and close statements.
and enclose the form references in brackets.
[forms]![Service_Work]![CustomerName]
 

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

Top