Help with params and variants??

jedcomyn

Registered User.
Local time
Today, 23:33
Joined
Jun 15, 2004
Messages
27
Hi,

Am having trouble with some code: i want to get a combo box to save an inputted value if it is not in the look up table.:

I am using this code

###########################################
Code:
Private Sub Title_NotInList(NewData As String, _
response As Integer)
response = _
AddItem_ToTable(NewData, "tblTitle", "title")


End Sub

Public Function AddItem_ToTable(strNewData As String, _
strTable As String, ParamArray strFields()) _
As Integer
On Error GoTo Err_Proc

Dim msg As String
Dim i As Integer, MAX As Integer
Dim Val As Variant
Dim rs As Recordset

' Initialize the return value to show standard error
' message.
AddItem_ToTable = acDataErrDisplay

' Prompt user to add the value.
If Not AddItem_Prompt(CStr(strFields(0)), strNewData) Then
' Exit if answer is No.
GoTo Exit_Proc
End If

' Determine the number of values sent.
MAX = UBound(strFields(), 1) + 1

' Check that parameters came in groups of two.
If (MAX < 2) Or (MAX Mod 2 > 0) Then
MsgBox "Incorrect Number of parameters Sent", _
vbInformation, "Programmer Error"
Exit Function
End If

' Open desired table.
Set rs = CurrentDb.OpenRecordset(strTable)
With rs
' Start new record.
.AddNew
' Add the new data to the specified field
.Fields(strFields(1)) = strNewData
i = 2
' Cycle through the rest of the parameters, prompting
' for values.
Do While i < MAX
Val = InputBox("Enter " & strFields(i), _
"Add Item to List")
.Fields(strFields(i + 1)) = Val
i = i + 2
Loop
.Update
End With

' Return that the data was added, which suppresses
' error message.
AddItem_ToTable = acDataErrAdded

Exit_Proc:
On Error Resume Next
rs.Close
Exit Function

Err_Proc:
MsgBox Err.Description, vbInformation, _
"AddItem_ToTable Error: " & Err.Number
Resume Exit_Proc

End Function
###########################################

But i always recieve an 'Incorrect Number of parameters Sent' error.
The lookup table is tbltitle and the filed name is title. i think i need another item after AddItem_ToTable(NewData, "tblTitle", "title") but not sure what.



Can anyone help??

Jed
 
Last edited by a moderator:
Look at my Examples in the FAQ - I've done one for A97 and for A2000+
 

Users who are viewing this thread

Back
Top Bottom