473,765 Members | 2,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

handling errors + last_inserted_i d + list_box search

Dear All;

I have 3 issues

1) On some of my tables I have unique indexes, so that
for example no two phone numbers can be the same.
When user enters phone number that already exists, a
scary error comes up with error number telling him
that it is a duplicate. I would like to catch this error
number xxxx and handle it so that I stop execution,
and report a MsbBox..... I hope this is possible.
Does anyone know the mechanisam for this, or
maybe has some sample code, or a usefull link....

2) Is there a last_inserted_i d in access, to find out
the value of last inserted row for a autoincrement
field?

3) I have a list box with large number of entries. I would
like to have a way to search it similar to (or exactly
the same) as the one automatically implemented by access
on combo boxes - as I type the search word
it displays the entries in the list that match the letters
typed. I think this is not already done? Does anyone have
somewhere that this can be downloaded, or has anyone tried to
do this already and can maybe share their experiances.

Hopefully the fact that I have 3 questions together doesnt
scare anybody off - it shows that I thought of them.

I am near the end of my project, and it would not be possible
to complete it without this group. Thanks to all that helped
or even read my messages.

Happy New Year

Damjan
Nov 12 '05 #1
1 1611
--
Scott McDaniel
CS Computer Software
Visual Basic - Access - Sql Server - ASP
<da*****@hotmai l.com> wrote in message
news:2f******** *************** ***@posting.goo gle.com...
Dear All;

I have 3 issues

1) On some of my tables I have unique indexes, so that
for example no two phone numbers can be the same.
When user enters phone number that already exists, a
scary error comes up with error number telling him
that it is a duplicate. I would like to catch this error
number xxxx and handle it so that I stop execution,
and report a MsbBox..... I hope this is possible.
Does anyone know the mechanisam for this, or
maybe has some sample code, or a usefull link....
Either catch this in the Form's error handler, or run code in the
BeforeUpdate event of the form to check this value before allowing it into
the database.

To catch this error in the FORM error handler (turn Key Preview ON) ... I
forget what the error number is, but you should be able to jot it down from
the current errors you're receiveing now.

On Error GoTo Proc_Err:

<your code module>

Proc_Err:
Select Case Err.Number
Case YourErrorNumber Here
MsgBox "Sorry this number is already in the db."
Case Else
End Select

In the BeforeUpdate event, you can use a DLookup to check for an existing
phone number. If a duplicate is found, Msgbox the user and Cancel the event.

2) Is there a last_inserted_i d in access, to find out
the value of last inserted row for a autoincrement
field?
Not if your datasource is a Jet database. You can use a DMax to get the
largest value entered (assuming you're NOT using random autonumbers), but
that's about as close as you'll get. Even then you are not guaranteed to get
the record that YOU just inserted, since someone else could have inserted
one immediately after you. You can always open a recordset, perform your
inserts, and then grab the Autonumber that was assigned to the record before
leaving the procedure ... that would give you the correct number.
3) I have a list box with large number of entries. I would
like to have a way to search it similar to (or exactly
the same) as the one automatically implemented by access
on combo boxes - as I type the search word
it displays the entries in the list that match the letters
typed. I think this is not already done? Does anyone have
somewhere that this can be downloaded, or has anyone tried to
do this already and can maybe share their experiances.
Put a textbox above your listbox, then in the Change event of your textbox:

Dim nCount As Integer
Dim strSearch As String

strSearch = Me.ctlSearch.Te xt

For nCount = 0 To Me.lstDocks.Lis tCount - 1
If Left(Me.lstDock s.Column(1, nCount), Len(strSearch)) = strSearch Then
Me.lstDocks.Sel ected(nCount) = True
Exit For
End If
Next

My textbox was named ctlSearch and my listbox was named lstDocks. You will
have to change the name of both to match those on your form. This code also
assumes a 2 column listbox, with the first column being hidden (i.e.
columnwidth = 0), with the search happening on the SECOND column ... since
the listcount of a listbox is 0 based, the first column is acutally
Column(0), the second is Column(1) etc etc


Hopefully the fact that I have 3 questions together doesnt
scare anybody off - it shows that I thought of them.

I am near the end of my project, and it would not be possible
to complete it without this group. Thanks to all that helped
or even read my messages.

Happy New Year

Damjan

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
6692
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that assert could be used to start an interactive debugger automatically. How do I realize that on a Linux machine using gcc?
3
3097
by: WindAndWaves | last post by:
I am writing error handling procedures at the moment. Here are some questions: 1. Can you write a procedure that picks up any error and deals with it no matter where it happens in the database? 2. Does Access keep a list of errors in a "secret" table? 3. Is there a way to handle common errors (such as - "you need to choose from the list" or "a related record is required in ....") with just one
4
2525
by: aaj | last post by:
Hi all I have an automated application, that runs in the middle of the night. If certain 'non system' errors occur (things like malformed files, missing files etc..), I send an automatic Email and write a record to the database. This is handled in a class. When these errors occur, once Emailed and written I want to just end the App, simple as that.
4
7618
by: James Radke | last post by:
Hello, I am looking for guidance on best practices to incorporate effective and complete error handling in an application written in VB.NET. If I have the following function in a class module (note that this class module represents the business layer of code NOT the gui layer): Public Function Test(ByVal Parm1 As Integer, ByVal Parm2 As Integer) As SqlDataReader ' Declare the SQL data layer class Dim oSQL As New...
4
1939
by: Al Williams | last post by:
Hi, I have error handling in place throughout my application. I also start the application wrapped in error handling code to catch any unexpected exceptions (i.e. exceptions that occur where I haven't placed error handling code). When I run my app from the IDE, the unhandled errors are caught by the error handling code in my Sub Main routine and the error details are logged to a text file and optionally e-mailed to me for follow-up.
2
2990
by: Petr Jakes | last post by:
I am a little bit confused by all possibilities for exceptions handling in Python (probably because I am not skilled enough??) I did try to search trough this list and reading Python tutorial about Errors and Exceptions but didn't find some "general" answer about exception handling policy (strategy). In the following example each row can IMHO raise an exception (if the Firebird service is not running for example, if the database is...
5
1736
by: csgraham74 | last post by:
Hi guys, Basically i have been developing in dotnet for a couple of years but ive had a few issues in regards to error handling. For example - I have a class that i call passing in a stored procedure and connection string as a path. My method returns a dataset. In my SP i have an output parameter which tells me whether the SP select is successful or not. If i get a error code passed back then i throw an exception this then returns...
35
3805
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks gets about 3 or so. It also gets very awkward in nested loops, where you want to check for normal loop processing in the loop condition, not errors. Yes, you could put some generic exit flag in the loop condition, but when you're simply done if...
2
1884
by: Omar Abid | last post by:
Reason of this project: Error handling is one of the most difficult thing that may afford a programmer. It isn't as easy as you think and handling errors in a program some time can make errors occur! Project details: 1- New solution for handling errors in .net 2- Try...Catch...Finally Block 3- Error handling sample
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.