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.
8 2057
Assuming you have a Field named [Tracking_Number] {STRING}, in a Table named tblOrders, here is a Template which you can use: - Dim strTrackingNum As String
-
Dim blnTrackingNumExists As Boolean
-
Dim strMsg As String
-
-
strTrackingNum = InputBox$("Please enter the Tracking Number.")
-
-
strMsg = "The Tracking Number [" & strTrackingNum & "] does not exist " & _
-
"in tblOrders!"
-
-
'blnTrackingNumExists returns True if the Tracking Number exists,
-
'and False if it doesn't
-
blnTrackingNumExists = DCount("*", "Employees", "[Tracking_Number] = '" & _
-
strTrackingNum & "'")
-
-
'User selected Cancel or OK with No Entry, bye - bye
-
If Len(strTrackingNum) = 0 Then
-
Exit Sub
-
Else
-
If blnTrackingNumExists Then 'Tracking Number does exist
-
'Code if Tracking Number exists in tblOrders
-
Else
-
'Code if Tracking Number does not exist
-
MsgBox strMsg, vbExclamation, "Tracking Number Not Found"
-
End If
-
End If
In Line #12 for Post #3, substitute tblOrders for Employees.
Thanks for the help, it worked great.
Thanks for the help, it worked great.
Glad it worked out for you.
I swear, i tried to change it but i couldn't figure it out. How do i make this work for a number field?
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: - Dim strTrackingNum As String
-
Dim blnTrackingNumExists As Boolean
-
Dim strMsg As String
-
-
strTrackingNum = InputBox$("Please enter the Tracking Number.")
-
-
strMsg = "The Tracking Number [" & strTrackingNum & "] does not exist " & _
-
"in tblOrders!"
-
-
'blnTrackingNumExists returns True if the Tracking Number exists,
-
'and False if it doesn't
-
blnTrackingNumExists = DCount("*", "tblOrders", "[Tracking_Number] = " & _
-
Val(strTrackingNum)) > 0
-
-
'User selected Cancel or OK with No Entry or it is Not a Number
-
If Len(strTrackingNum) = 0 Or Not IsNumeric(strTrackingNum) Then
-
Exit Sub
-
Else
-
If blnTrackingNumExists Then 'Tracking Number does exist
-
'Code if Tracking Number exists in tblOrders
-
MsgBox "Yes it's alive!"
-
Else
-
'Code if Tracking Number does not exist
-
MsgBox strMsg, vbExclamation, "Tracking Number Not Found"
-
End If
-
End If
Thanks again. You have really helped.
Thanks again. You have really helped.
The pleasure is all mine.
Sign in to post your reply or Sign up for a free account.
Similar topics
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>...
|
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:...
|
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
|
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"...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |