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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Not in List" event won't work 1

Status
Not open for further replies.

vanlanjl

Programmer
Jan 14, 2009
93
US
I cannot get the not in list event to work right.

On my form I have a combo box named "cboChargeCode"

I have a table named "tblChargeCode"

I would like it so when you enter a value into the cbohargeCOde that is not listed it will alert you and ask you if you would like to add such item.

My code
Code:
Private Sub ChargeCode_NotInList(NewData As String, Response As Integer)
Dim strSQL As String
Dim i As interger
Dim MSg As String

'Exit this sub if the combo box is cleared
If NewData = "" Then Exit Sub

MSg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
MSg = MSg & "Do you want to add it?"

i = MSg(MSg, vbQuestion + vbYesNo, "Unknown Charge Code...")
If i = vbYes Then
    strsql = "Insert into tblChargeCode ([strChargeCode])" & CurrentDb.excute strSQL, dbFailOnError
    Response = acDataErrAdded
Else
    Response = acDataErrContinue
End If

error occurs on line:
Code:
strsql = "Insert into tblChargeCode ([strChargeCode])" & CurrentDb.excute strSQL, dbFailOnError

I got this code form Microsoft so...
not sure what is going on or why it doesnt work, any help would be awesome!
Thanks
 
Replace this:
strsql = "Insert into tblChargeCode ([strChargeCode])" & CurrentDb.excute strSQL, dbFail
with this:
Code:
strsql = "Insert into tblChargeCode ([strChargeCode])" & _
  " VALUES ('" & NewData & "')"
CurrentDb.excute strSQL, dbFail

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
you are correct that was a typo
thanks

but still not working
 
PHV

Made changes. Assumed that it was a two line change. No changes.

Receive Compile Error - User-defined type not found

Highlighting in yellow line 1
and in blue line 3
 
Okay aftera couple stupid spelling errors on my part I have gotten it open the MsgBox but upon clicking okay to add to tbl i receive the following:

Run-time error '3127':
The INSERT INTO statement contains the following unknown field name: 'strChargeCode'. make sure you have typed the name correctly and try the operation again.

highlighting:

Code:
CurrentDB.Execute strSQL, dbFail
 
Now my table is structured as follows

name: tblChargeCode
Feilds: DataType:
ChargeCode (PK) Number
 
changed
Code:
strsql = "Insert into tblChargeCode ([strChargeCode])" &

to

Code:
strsql = "Insert into tblChargeCode ([ChargeCode])" &

Works perfect! Thanks to everyone that contributed!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top