Multiple-variable Functions

J

jtertin

This is driving me crazy, and I am sure it is something small and
syntax-related that is holding me up:

My Function:
===========================================
Public Function RenameRecipe(RecipeNo As Integer, RecipeName As
String)
Dim Conn1 As ADODB.Connection
Dim Cmd1 As ADODB.Command
Dim rs1 As ADODB.Recordset

' Establish connection.
Set Conn1 = New ADODB.Connection
Conn1.Open "DSN=ESE_DM;UID=sa;PWD=" + stDatabasePassword + ";"

' Execute SP
Set Cmd1 = New ADODB.Command
Cmd1.ActiveConnection = Conn1
Cmd1.CommandText = "UpdateRecipeName"
Cmd1.CommandType = adCmdStoredProc
Cmd1.Parameters.Refresh
Cmd1.Parameters(1).Value = RecipeNo
Cmd1.Parameters(2).Value = RecipeName
Set rs1 = Cmd1.Execute()
End Function
===========================================

My Call (as tied to a button's click event):
===========================================
Private Sub btnApply_Click()
MsgBox (txtRecNo.Value)
MsgBox (txtNewName.Value)
RenameRecipe (txtRecNo.Value, txtNewName.Value)
cboRecipe.Requery
End Sub
===========================================

The call "RenameRecipe (txtRecNo.Value, txtNewName.Value)" is
highlighted in red and indicates "Compile error: Expected: =". If I
put a bogus "=1" after the call, it works fine until returning from
the RenameRecipe function where it not surprisingly returns "Run-time
error '424': Object Required".

I am certain it has to do with the RenameRecipe function taking
multiple input variables as I have MANY functions in this program
(with only one input variable) that do not have issues. WHAT am I
missing!?
 
J

jtertin

PS:
1. The "MsgBox"es are for debugging
2. I have already tried assigning the textbox values to variables and
sending the variables to the function, but does not make a
difference. The function itself is executed perfectly and the
database stored procedure IS executed without error. It is when focus
returns to the calling function (the button click event) that I am
having issues.

If it makes a difference, the RenameRecipe function is in a separate
public module along with all of my functions (which are working fine
except for this one).
 
D

Douglas J. Steele

Since RenameRecipe doesn't return a value, there's no reason it needs to be
a function. Try changing it to a Sub.

Alternatively, change how you're invoking it from

RenameRecipe (txtRecNo.Value, txtNewName.Value)

to either

Call RenameRecipe (txtRecNo.Value, txtNewName.Value)

or

RenameRecipe txtRecNo.Value, txtNewName.Value
 

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


Top