Hi all,
I have a form that uses the code listed below on the after update of a combo box and list box to search for a selected Name.
(code for afterupdate for combo box) - Private Sub Combo73_AfterUpdate()
-
' Find the record that matches the control.
-
Me.RecordsetClone.FindFirst "[Name] = '" & Me![Combo73] & "'"
-
Me.Bookmark = Me.RecordsetClone.Bookmark
-
End Sub
(code for afterupdate for list box) - Private Sub List75_AfterUpdate()
-
' Find the record that matches the control.
-
Me.RecordsetClone.FindFirst "[Name] = '" & Me![List75] & "'"
-
Me.Bookmark = Me.RecordsetClone.Bookmark
-
End Sub
How would I add the ability to display an error message if the user tries to search for a Name that doesn't exist in the records?
7 2053
Hi all,
I have a form that uses the code listed below on the after update of a combo box and list box to search for a selected Name.
(code for afterupdate for combo box) - Private Sub Combo73_AfterUpdate()
-
' Find the record that matches the control.
-
Me.RecordsetClone.FindFirst "[Name] = '" & Me![Combo73] & "'"
-
Me.Bookmark = Me.RecordsetClone.Bookmark
-
End Sub
(code for afterupdate for list box) - Private Sub List75_AfterUpdate()
-
' Find the record that matches the control.
-
Me.RecordsetClone.FindFirst "[Name] = '" & Me![List75] & "'"
-
Me.Bookmark = Me.RecordsetClone.Bookmark
-
End Sub
How would I add the ability to display an error message if the user tries to search for a Name that doesn't exist in the records?
-
Private Sub Combo73_AfterUpdate()
-
Dim strCriteria As String
-
Dim rst As DAO.Recordset
-
-
Set rst = Me.RecordsetClone
-
-
strCriteria = "[Name] = '" & Me![Combo73] & "'"
-
-
rst.FindFirst strCriteria
-
-
If rst.NoMatch Then
-
MsgBox "A Name of [" & UCase$(Me![Combo73]) & "] was not found in " & _
-
"the Database!", vbExclamation, "Name not Found"
-
Else
-
Me.Bookmark = rst.Bookmark
-
End If
-
End Sub
-
Private Sub Combo73_AfterUpdate()
-
Dim strCriteria As String
-
Dim rst As DAO.Recordset
-
-
Set rst = Me.RecordsetClone
-
-
strCriteria = "[Name] = '" & Me![Combo73] & "'"
-
-
rst.FindFirst strCriteria
-
-
If rst.NoMatch Then
-
MsgBox "A Name of [" & UCase$(Me![Combo73]) & "] was not found in " & _
-
"the Database!", vbExclamation, "Name not Found"
-
Else
-
Me.Bookmark = rst.Bookmark
-
End If
-
End Sub
Thanks ADezzi, it works like a charm! I tested it to see what would happen if the field was NULL and I get a runtime error ... How do I fix that?
Thanks ADezzi, it works like a charm! I tested it to see what would happen if the field was NULL and I get a runtime error ... How do I fix that?
Just add Line #5 -
Private Sub Combo73_AfterUpdate()
-
Dim strCriteria As String
-
Dim rst As DAO.Recordset
-
-
If IsNull(Me![Combo73]) Then Exit Sub
-
-
Set rst = Me.RecordsetClone
-
-
strCriteria = "[LastName] = '" & Me![Combo73] & "'"
-
-
rst.FindFirst strCriteria
-
-
If rst.NoMatch Then
-
MsgBox "A Name of [" & UCase$(Me![Combo73]) & "] was not found in " & _
-
"the Database!", vbExclamation, "Name not Found"
-
Else
-
Me.Bookmark = rst.Bookmark
-
End If
-
End Sub
Just add Line #5 -
Private Sub Combo73_AfterUpdate()
-
Dim strCriteria As String
-
Dim rst As DAO.Recordset
-
-
If IsNull(Me![Combo73]) Then Exit Sub
-
-
Set rst = Me.RecordsetClone
-
-
strCriteria = "[LastName] = '" & Me![Combo73] & "'"
-
-
rst.FindFirst strCriteria
-
-
If rst.NoMatch Then
-
MsgBox "A Name of [" & UCase$(Me![Combo73]) & "] was not found in " & _
-
"the Database!", vbExclamation, "Name not Found"
-
Else
-
Me.Bookmark = rst.Bookmark
-
End If
-
End Sub
Thanks so much for the help, ADezzi!!!
Thanks so much for the help, ADezzi!!!
Anytime, that's why we are all here.
Anytime, that's why we are all here.
Hi Again,
I'm trying to do more error handling etc, and i'm wondering: Can there be a way to add a line in the above code to open a form if the Name is found? Does this make sense: - Private Sub Combo33_AfterUpdate()
-
Dim strCriteria As String
-
Dim rst As DAO.Recordset
-
-
Set rst = Me.RecordsetClone
-
-
strCriteria = "[Name] = '" & Me![Combo33] & "'"
-
-
rst.FindFirst strCriteria
-
-
If rst.NoMatch Then
-
MsgBox "A Name of [" & UCase$(Me![Combo73]) & "] was not found in " & _
-
"the Database!", vbExclamation, "Name not Found"
-
Else
-
Me.Bookmark = rst.Bookmark
-
On Error GoTo Err_Command18_Click
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stDocName = "fm_lookup_result"
-
-
stLinkCriteria = "[Prod_Spec]=" & "'" & Me![Combo31] & "'"
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
-
Exit_Command18_Click:
-
Exit Sub
-
-
Err_Command18_Click:
-
MsgBox Err.Description
-
Resume Exit_Command18_Click
-
-
End If
-
End Sub
-
Private Sub Combo73_AfterUpdate()
-
On Error GoTo Err_Combo73_AfterUpdate
-
Dim strCriteria As String
-
Dim rst As DAO.Recordset
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stDocName = "fm_lookup_result"
-
stLinkCriteria = "[Prod_Spec]=" & "'" & Me![Combo31] & "'"
-
-
If IsNull(Me![Combo73]) Then Exit Sub
-
-
Set rst = Me.RecordsetClone
-
-
strCriteria = "[LastName] = '" & Me![Combo73] & "'"
-
-
rst.FindFirst strCriteria
-
-
If rst.NoMatch Then
-
MsgBox "A Name of [" & UCase$(Me![Combo73]) & "] was not found in " & _
-
"the Database!", vbExclamation, "Name not Found"
-
Else
-
'Guess you won't be needing this, now
-
'Me.Bookmark = rst.Bookmark
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
End If
-
-
Exit_Combo73_AfterUpdate:
-
Exit Sub
-
-
Err_Combo73_AfterUpdate:
-
MsgBox Err.Description, vbExclamation, "Error in Combo73_AfterUpdate()"
-
Resume Exit_Combo73_AfterUpdate
-
End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Xeon |
last post by:
Hi,
Is there anyway to set a custom error handler which is actually a
method of a class? i.e. setting the method eh() of class foo as error
handler in the snippet below.
class foo {
function...
|
by: WSeeger |
last post by:
When creating a new class, is it encouraged to always include error
handling routines within your LET and GET procedures? It's seems that
most text books never seem to include much about error...
|
by: Steve Jorgensen |
last post by:
When writing VB or VBA code that works with databases or other external
libraries that cannot be trusted to automatically do the right thing when
references to their objects are arbitrarily...
|
by: Anthony England |
last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled
error is encountered, but it seems that this also happens when the variable
is defined as private at form-level.
So...
|
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...
|
by: Lysander |
last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access...
|
by: adam.timberlake |
last post by:
I've just finished reading the article below which goes into some
depth about exceptions. The article was rather lucid and so I
understand how to implement it all, the thing I'm having trouble with...
|
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...
|
by: nguyenminhhai |
last post by:
Hi everyone, I'm reading "The C++ Programming Language" (Bjarne
Stroustrup, 3rd edition). At page 193, he said "Doing error handling
using the same level of abstraction as the code that caused the...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
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...
| |