473,396 Members | 2,014 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,396 software developers and data experts.

handling errors + last_inserted_id + 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_id 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 1592
--
Scott McDaniel
CS Computer Software
Visual Basic - Access - Sql Server - ASP
<da*****@hotmail.com> wrote in message
news:2f**************************@posting.google.c om...
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 YourErrorNumberHere
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_id 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.Text

For nCount = 0 To Me.lstDocks.ListCount - 1
If Left(Me.lstDocks.Column(1, nCount), Len(strSearch)) = strSearch Then
Me.lstDocks.Selected(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
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...
3
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?...
4
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...
4
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...
4
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...
2
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...
5
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...
35
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.