473,385 Members | 1,769 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,385 software developers and data experts.

Avoiding runtime error if a record does not exist - HELP PLEASE

Hi,

So i have a huge database that manages Mining Tenements (Titles)...

I have created a specific form with a drop down list of the list of tenements in the database. now i can either type or select the tenement then press the enter button and it brings up another form with all of the tenements details.... which works great.

but with this selection form. i usually type the tenement is as its a lot quicker then searching through a list of 3500... if i type in a number that does not exist in the database, i get a runtime error...

so my question is, what do i need to do to put a check inbetween pressing the button to load the new form to check if the tenement exits in the database and if it doesnt to bring up a message box to say so and go back to the selection form.

i know this probably seems easy to most of you guys.. but i'm learning VBA as i go along!! first time i've had to check for something like this..

your help is greatly appreciated
Jun 7 '12 #1
3 2142
Hi Luthrien,

Are you typing the tenement in a text box or something and trying to find it from a record set?

If you are just checking for a specific record in a record set, then please try the below:

Expand|Select|Wrap|Line Numbers
  1. rstRecSet.FindFirst "[Tenement_Field_Name] = "Tenement to be searched""
This would take you to the specific record where it appears first.

then use below to see the value from pointed record

Expand|Select|Wrap|Line Numbers
  1. rstRecSet.Fields(FieldNum).value
FieldNum - the position where the specific field(Tenement_Field_Name) appears in the record set

Note: If the Tenement that you are searching for is not found in the Tenement_Field_Name, then it wouldn't throw an error message, however the pointer stays in the first record of the recordset.

Thanks,
Naren
Jun 7 '12 #2
naren,

thanks for your reply... basically the dropdown box is filled in with the tenement numbers from the table they are held in..

if i start typing then it auto-fills.. but sometimes i just continue typing and make a mistake and press the button to load hte form without even looking at what i typed... the recordset is already loaded in the drop down box...
Jun 7 '12 #3
in that case, i think the best idea would be handeling it using afterupdate event of the combobox. Please see below for an idea

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmbSearchTenement_AfterUpdate()
  2.     On Error GoTo lblErr
  3.     .
  4.     .
  5.     .
  6.     Your Code that finds the record and display the next form
  7.     .
  8.     .
  9.     .
  10.     Exit Sub
  11. lblErr:
  12.     If Err.Number = 123 Then
  13.        MsgBox "Please enter a valid tenement"
  14.        NextForm.Visible = False
  15.        CurrentForm.Visible = True
  16.     Else
  17.        MsgBox Err.Description & " - cmbSearchTenement_AfterUpdate"
  18.     Endif
  19. End Sub
  20.  
as and when you get any error in the block of code between On Error statement and the Exit Sub statement, the control would come down to lblErr: part. Here you can handle all errors. I am just checking the error number of the specific error and showing a relevent message to the user. otherwise, if it is an unknown error, then i am showing the application generated error description to the user.

I use this sort of error handling in all functions and procedures I write. Showing function/Procedure name in the error message will make it easier when you want to know where an error occurs exactly.

Note: the Err.Number 123 is not the correct error number. Please check the error number for your error and use it.
Jun 7 '12 #4

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

Similar topics

8
by: swathky | last post by:
I've tried mutiple things but no go -- (sorry this is so long) I'm collecting a 5 digit number in an input box function and all works fine until a number is passed that doesn't exist in the...
0
by: Jamey | last post by:
I perused old posts for an answer to this for at least an hour, and I've found a work-around, but no definitive answer. Synopsis of the problem: On NotInList or ctl.Requery commands where a...
3
by: bill_hounslow | last post by:
I'm trying to transfer data from one Sql Server into a table on another, using a simple INSERT query in an Access database with links to tables on both servers (the reasons for this are complicated...
4
by: barbara_dave | last post by:
Hi all, We have a Access database used by multiple user. For some reason the database get a "Error" record. When doing search or record pointer point to this record, we get run time error...
2
by: Matthew Louden | last post by:
I want to read how many records in the table, and insert a record with id field which increment the counter by 1. However, I had the following runtime on Dim s As Integer = CInt(dr("t")). Since "t"...
6
by: Bill Patel | last post by:
I am getting Runtime error on line 50. Please Help. Thank You Bill 1 <%@ Page Language="VB" %> 2 <%@ import Namespace="System.Data" %> 3 <%@ import Namespace="System.Data.SqlClient"...
4
by: kristan.mcdonald | last post by:
Probably a simple one, but I've found nothing in groups or google so here goes; trying to deploy a simple .net asp app to our web server, which has been hardended as it's public facing. It's only...
8
by: g_man | last post by:
I am trying trap Runtime error 3022 (duplicates) in the click event of a command button that closes the form. I have code in the Form_Error event that does a good job of providing a more meaningful...
2
by: Pwz | last post by:
well I dont have enough knowledgment about VB and I have some problem with one program, the program is simple I have to appear some clasfication automatically in the column b this is a part of the...
3
by: Jim Armstrong | last post by:
Hello all - This is driving me crazy. I have a table called tblClients - very simple, has the following fields: taxID (PK) ClientName SalesName The main form of my application allows a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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
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...

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.