473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

"Not in list" event for Access 2007

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
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub ChargeCode_NotInList(NewData As String, Response As Integer)
  3. Dim strSQL As String
  4. Dim i As interger
  5. Dim MSg As String
  6.  
  7. 'Exit this sub if the combo box is cleared
  8. If NewData = "" Then Exit Sub
  9.  
  10. MSg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
  11. MSg = MSg & "Do you want to add it?"
  12.  
  13. i = MSgBox(MSg, vbQuestion + vbYesNo, "Unknown Charge Code...")
  14. If i = vbYes Then
  15.     strsql = "Insert into tblChargeCode ([strChargeCode])" & CurrentDb.excute strSQL, dbFailOnError
  16.     Response = acDataErrAdded
  17. Else
  18.     Response = acDataErrContinue
  19. End If
  20.  
error occurs on line:
Expand|Select|Wrap|Line Numbers
  1. strsql = "Insert into tblChargeCode ([strChargeCode])" & CurrentDb.excute strSQL, dbFailOnError
  2.  
I got this code form Microsoft so...
not sure what is going on or why it doesnt work, any help would be awesome!
Thanks
Apr 1 '09 #1
6 6704
RuralGuy
375 Expert 256MB
Recheck where you got the code from (Microsoft). You'll see it is not the same.
Apr 1 '09 #2
I figured it out.
Expand|Select|Wrap|Line Numbers
  1.  
  2. Option Compare Database
  3.  
  4. Private Sub cboChargeCode_NotInList(NewData As String, Response As Integer)
  5. Dim strSQL As String
  6. Dim i As Integer
  7. Dim MSg As String
  8.  
  9. 'Exit this sub if the combo box is cleared
  10. If NewData = "" Then Exit Sub
  11.  
  12. MSg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
  13. MSg = MSg & "Do you want to add it?"
  14.  
  15. i = MsgBox(MSg, vbQuestion + vbYesNo, "Unknown Charge Code...")
  16. If i = vbYes Then
  17.     strSQL = "Insert into tblChargeCode ([ChargeCode])" & " VALUES ('" & NewData & "')"
  18.     CurrentDb.Execute strSQL, dbFail
  19.     Response = acDataErrAdded
  20. Else
  21.     Response = acDataErrContinue
  22. End If
  23. End Sub
  24.  
Apr 1 '09 #3
RuralGuy
375 Expert 256MB
Excellent! Glad you got it sorted.
Apr 1 '09 #4
Hey I'm Felton and here for the first time. I came across this thread and I find It truly useful & it helped me out much. I hope to give something back and aid others like you aided me.
Dec 8 '11 #5
RuralGuy
375 Expert 256MB
Welcome. Glad we could help.
Dec 8 '11 #6
NeoPa
32,556 Expert Mod 16PB
Suspicion alert:
Why would this help anyone but the OP? It's not like it's a common mistake to make, and it's all about the OP's mistake.

If 92Felton goes on to post normally then no problem. If, on the other hand, they post anything suspicious, then this should not be taken to indicate their motives are pure.
Dec 9 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kamal | last post by:
I am trying to send mail through smtp. smtp service is running on my machine. But every time during the smtpmail.send(msg) call gives "Could not access 'CDO.Message' object." error. Could some...
1
by: Jens Øster | last post by:
Hi I am writing a ASP.NET web application that must sent some e-mails. I get the exception “Could not access 'CDO.Message' object” when I call SmtpMail.Send. This only happens when I send...
3
by: Jens | last post by:
Hi I am writing a ASP.NET web application that must sent some e-mails. I get the exception “Could not access 'CDO.Message' object” when I call SmtpMail.Send. This only happens when I send...
4
by: Liz Patton | last post by:
Here's the exception: System.Exception: Unable to send mail: Could not access 'CDO.Message' object. ---> System.Web.HttpException: Could not access 'CDO.Message' object. --->...
2
by: chuckdfoster | last post by:
I am getting a "Could Not Access CDO.Message Object" Error when I try to use the following code to send an email via ASP.NET. When I run this on one machine it works, on another one it doesn't. ...
5
by: lds | last post by:
I am getting the following error: The "SendUsing" configuration value is invalid. Description: An unhandled exception occurred during the execution of the current web request. Please review the...
1
by: Jason | last post by:
I am trying to send mail via SMTP, using VB.NET on XP. I keep getting this error: "Could not access 'CDO.Message' object." (I can send mail fine via VB6, using CDONTS.) I have added a reference...
2
by: Rico | last post by:
Hello, Is there any way to get rid of or replacing the error message that pops up when you enter a combo box item that isn't in the list? I've tried using the Not In List event, but there is...
3
by: PW | last post by:
Hi, One of our clients is getting that error when they are trying to save a record but I can not duplicate it here. The data is on another PC and is linked to two workstations. The code...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.