R
rocketD
Hi All,
I posted a couple days ago about a database I'm working on, where I
have to allow users to add data to lookup tables while they are in a
form without using a bunch of subforms. Someone directed me to this
code
http://www.developerbarn.com/access-database-samples/251-combo-box-add-entry-not-list.html
and I've tried to adapt it, but I don't really know what I'm doing. I
need to be able to add 2 fields to the lookup table, one which is the
new data the user types in (fieldname uww), and the other which is the
areaID # selected in the previous field.
The error I get when I test this in the form is "Run-time error
'3346': # of query values and destination fields are not the same." I
think the problem is in the second line of my strSQL command, but I
don't know how to fix it; what I've tried hasn't worked. Can someone
please look at the code below and make a suggestion?
Thanks,
Dara
Private Sub uww_NotInList(NewData As String, Response As Integer)
Dim ctl As Control
Dim strSQL As String
Set ctl = Me!uww
If MsgBox("Value is not in list. Add it?", _
vbOKCancel) = vbOK Then
Response = acDataErrAdded
strSQL = "INSERT INTO lkpChargeCode(chargeCode, areaID) VALUES( ' "
strSQL = strSQL & NewData & ", " & Me.area & " ' );"
CurrentDb.Execute strSQL
Else
Response = acDataErrContinue
ctl.Undo
End If
End Sub
I posted a couple days ago about a database I'm working on, where I
have to allow users to add data to lookup tables while they are in a
form without using a bunch of subforms. Someone directed me to this
code
http://www.developerbarn.com/access-database-samples/251-combo-box-add-entry-not-list.html
and I've tried to adapt it, but I don't really know what I'm doing. I
need to be able to add 2 fields to the lookup table, one which is the
new data the user types in (fieldname uww), and the other which is the
areaID # selected in the previous field.
The error I get when I test this in the form is "Run-time error
'3346': # of query values and destination fields are not the same." I
think the problem is in the second line of my strSQL command, but I
don't know how to fix it; what I've tried hasn't worked. Can someone
please look at the code below and make a suggestion?
Thanks,
Dara
Private Sub uww_NotInList(NewData As String, Response As Integer)
Dim ctl As Control
Dim strSQL As String
Set ctl = Me!uww
If MsgBox("Value is not in list. Add it?", _
vbOKCancel) = vbOK Then
Response = acDataErrAdded
strSQL = "INSERT INTO lkpChargeCode(chargeCode, areaID) VALUES( ' "
strSQL = strSQL & NewData & ", " & Me.area & " ' );"
CurrentDb.Execute strSQL
Else
Response = acDataErrContinue
ctl.Undo
End If
End Sub