473,396 Members | 2,061 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.

Display message box when search is not succesful.

I am using the following code on a search page.

myvalue = InputBox("Please enter the Tracking Number.")

stDocName = "Inspection_form"
stLinkCriteria = "[tracking_number]=" & "'" & [myvalue] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria, acReadOnly

What i would like to know is how to open another form or msgbox if the [tracking_number] does not exist as a record.

Thanks in advance.
Sep 27 '08 #1
8 2057
ADezii
8,834 Expert 8TB
Assuming you have a Field named [Tracking_Number] {STRING}, in a Table named tblOrders, here is a Template which you can use:
Expand|Select|Wrap|Line Numbers
  1. Dim strTrackingNum As String
  2. Dim blnTrackingNumExists As Boolean
  3. Dim strMsg As String
  4.  
  5. strTrackingNum = InputBox$("Please enter the Tracking Number.")
  6.  
  7. strMsg = "The Tracking Number [" & strTrackingNum & "] does not exist " & _
  8.          "in tblOrders!"
  9.  
  10. 'blnTrackingNumExists returns True if the Tracking Number exists,
  11. 'and False if it doesn't
  12. blnTrackingNumExists = DCount("*", "Employees", "[Tracking_Number] = '" & _
  13.                                     strTrackingNum & "'")
  14.  
  15. 'User selected Cancel or OK with No Entry, bye - bye
  16. If Len(strTrackingNum) = 0 Then
  17.   Exit Sub
  18. Else
  19.   If blnTrackingNumExists Then      'Tracking Number does exist
  20.     'Code if Tracking Number exists in tblOrders
  21.   Else
  22.     'Code if Tracking Number does not exist
  23.     MsgBox strMsg, vbExclamation, "Tracking Number Not Found"
  24.   End If
  25. End If
Sep 27 '08 #2
ADezii
8,834 Expert 8TB
In Line #12 for Post #3, substitute tblOrders for Employees.
Sep 27 '08 #3
Thanks for the help, it worked great.
Sep 27 '08 #4
ADezii
8,834 Expert 8TB
Thanks for the help, it worked great.
Glad it worked out for you.
Sep 28 '08 #5
I swear, i tried to change it but i couldn't figure it out. How do i make this work for a number field?
Sep 29 '08 #6
ADezii
8,834 Expert 8TB
I swear, i tried to change it but i couldn't figure it out. How do i make this work for a number field?
This would be the closest approach to what you already have:
Expand|Select|Wrap|Line Numbers
  1. Dim strTrackingNum As String
  2. Dim blnTrackingNumExists As Boolean
  3. Dim strMsg As String
  4.  
  5. strTrackingNum = InputBox$("Please enter the Tracking Number.")
  6.  
  7. strMsg = "The Tracking Number [" & strTrackingNum & "] does not exist " & _
  8.          "in tblOrders!"
  9.  
  10. 'blnTrackingNumExists returns True if the Tracking Number exists,
  11. 'and False if it doesn't
  12. blnTrackingNumExists = DCount("*", "tblOrders", "[Tracking_Number] = " & _
  13.                        Val(strTrackingNum)) > 0
  14.  
  15. 'User selected Cancel or OK with No Entry or it is Not a Number
  16. If Len(strTrackingNum) = 0 Or Not IsNumeric(strTrackingNum) Then
  17.   Exit Sub
  18. Else
  19.   If blnTrackingNumExists Then      'Tracking Number does exist
  20.     'Code if Tracking Number exists in tblOrders
  21.     MsgBox "Yes it's alive!"
  22.   Else
  23.     'Code if Tracking Number does not exist
  24.     MsgBox strMsg, vbExclamation, "Tracking Number Not Found"
  25.   End If
  26. End If
Sep 29 '08 #7
Thanks again. You have really helped.
Sep 29 '08 #8
ADezii
8,834 Expert 8TB
Thanks again. You have really helped.
The pleasure is all mine.
Sep 30 '08 #9

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

Similar topics

6
by: HartSA | last post by:
Here is the relevent part of my code. I am trying to learn ASP. <body> <table border="0" cellspacing="0" cellpadding="0"> <form name="frmSearch1a" method="get"> <tr> <td align=center>...
5
by: Miguel Dias Moura | last post by:
Hello, I have a search form in an ASP.NET/VB page. The form has the input text box and the button "search". The keywords are passed in the URL to results.aspx. Here is an example:...
3
by: Miguel Dias Moura | last post by:
Hello, I am working in ASP.NET/VB and I need to see a string value. Howe can I display the string values and also only one of the values? Thanks, Miguel
6
by: dee | last post by:
Here is a a list of my hyperlinks in my home page: <A class="theclass" href="Default.aspx">Home</A> <A class="theclass" href="Search.aspx">Search</A> <A class="theclass"...
3
by: Chris Saunders | last post by:
May be a dumb question but I have been unable to find the answer on my own. I wish to display a help file (*.chm) can anyone help? I attempted using "displaying help file" as a search in MSDN but...
2
by: kev | last post by:
Hi Folks, I have created a search query in which it successfully returns correct results. When there are no records returned, instead of giving out a blank form i created a pop-up msg which is...
1
by: Reef81 | last post by:
Does anyone know a way to have the search parameters displayed in the query or report? For example, if I set up a parameter to search all entries in my table, is there a way to have the search...
2
by: J055 | last post by:
Hi I need to search a number of DataTables within a DataSet (with some relationships) and then display the filtered results in a GridView. The Columns that need to be displayed come from 2 of...
2
by: Se0ng | last post by:
How to immediate show the data result from database when successful insert date into database, I mean no need to exit and re-enter the form, can any 1 give some idea or any guide? I try using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.