473,785 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handling error

56 New Member
Hi all,
I have a listbox which lists all the accounts, and I would like to handle error when user did not select any account in the list box but then click on "view/edit" button. The following is my code. However, I keep on having the blank account form open on the top of the error message. Any idea? thanks

Private Sub cmdEditAcct_Cli ck()
Dim Title As String
Dim Msg As String

On Error GoTo Err_cmdEditAcct _Click

DoCmd.RunMacro "mcrEditAcc t" 'open form
[Forms]![fdlgEditAccount]![txtUsername] = [Forms]![frmEdit]![txtUsername]
Exit_cmdEditAcc t_Click:
Exit Sub

Err_cmdEditAcct _Click:
Select Case Err
Case 2448 'No account selected
Title = "Select Account"
Msg = "You must first select an Account to make correction."
Msg = Msg & " Please click on an Account in the All Accounts listbox."
Beep
MsgBox Msg, vbExclamation, Title
Resume Exit_cmdEditAcc t_Click
Case Else
MsgBox Error$
Resume Exit_cmdEditAcc t_Click
End Select
End sub
Dec 2 '09 #1
5 1779
missinglinq
3,532 Recognized Expert Specialist
Error Code 2448 is an Access defined error: "You cannot assign a value to this
object." You cannot simply use it to mean whatever you want! Any error handled in this manner has to be an Access defined error, and there is no Access defined error for something like this! You have to use some custom code, something like this, replacing AllAccountsList box with the actual name of your listbox:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdEditAcct_Click()
  2. Dim Title As String
  3. Dim Msg As String
  4.  
  5. If IsNull(Me.AllAccountsListbox) Then
  6.   Title = "Select Account"
  7.   Msg = "You must first select an Account to make correction."
  8.   Msg = Msg & " Please click on an Account in the All Accounts listbox."
  9.   Beep
  10.   MsgBox Msg, vbExclamation, Title
  11.   Me.AllAccountsListbox.SetFocus
  12. Else
  13.  DoCmd.RunMacro "mcrEditAcct" 'open form
  14.  [Forms]![fdlgEditAccount]![txtUsername] = [Forms]![frmEdit]![txtUsername]
  15. End If
  16. End sub
Linq ;0)>
Dec 2 '09 #2
bluemoon9
56 New Member
Hi Ling,
I've tried your code, but it still open the form even though I did not choose anything in the listbox.

Any help?
thanks!
Dec 2 '09 #3
bluemoon9
56 New Member
In addition, it open a blank form with the error 2448.
thanks!
Dec 2 '09 #4
missinglinq
3,532 Recognized Expert Specialist
If you replaced AllAccountsList box in the code I gave you with the actual name of your listbox,

DoCmd.RunMacro "mcrEditAcc t"

should not run if no selection has been made from the listbox.

You need to post the exact code you're currently using.

Linq ;0)>

P.S. You do have the Multi-select Property of the Listbox set to No, don't you? It has to be for this kind of thing.
Dec 2 '09 #5
bluemoon9
56 New Member
Yes, I did. I did put the lstPtAccount list box. I also set the multi selection to No and it did not work.
My form is like this, when a user select a cutomer ID from the cboCustomer, it will show all the accounts in the listbox under the selected customer. So eveytime the user selects a new customerID from the customer combo box, it requery the listbox. Would this make the listbox to be "NotNull" all the time since the user might have selected an account in the list box for the 1st selected customer? So when it comes to the second customer, even though nothing has been selected in the listbox, the listbox will also "is not null"?

thanks!

Elaine
Dec 3 '09 #6

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

Similar topics

3
1844
by: muser | last post by:
I'm writing a function that isn't showing as an error during compilation, but it is at run time. The exception it is throwing informs me that it is due to my two pointers in that function. It is an access violation error, where the memory can't be read. I'll list the things I've tried in order to resolve the problem so that no one will suggest the same thing. I've tried initialising AN as a just a character pointer, then just as a...
1
1395
by: Pachydermitis | last post by:
Hi everyone, How do I get the error message? I have a very long sproc that needs to be done in one transaction. I have an error happening somewhere in the middle, but with a low enough severity it doesn't terminate the procedure. To make sure I don't miss any errors, I am storing @@error after every statement: If @Error<=@@error Set @Error=@@error that way at the end I can say if @error<>0 rollback trans. How do I get the error...
1
1818
by: Phillip | last post by:
I just ran into this problem also. (undocumented exception thrown when Streamwriter is handed a buffer with wierd characters in it). I was also able to get around it by specifying utf8 as the encoding for Streamwriter. (Thank you Amy L!) But I have some questions: 1- Isn't utf8 supposed to be the default mode for streamwriter? If so why does specifying the default fix the problem?
3
1124
by: Nikhil Patel | last post by:
Hi all, I have a drop down in an asp.net form defined as below: <asp:DropDownList id="dropDownLeaseType" runat="server" OnSelectedIndexChanged="LeaseTypeChanged"></asp:DropDownList> I have declared a javascript function as below: <SCRIPT type="text/javascript"> function LeaseTypeChanged() { WebComboWinningStructure.SelectedIndex =
0
1029
by: Joost | last post by:
Hello all, I am currently developping an intranet website for my company and I encountered a strange thing. I have a global error handler (application_error) in my global.asax file which should handle all the unhandled exceptions. The strange thing is, it only catches unhandled exceptions sometimes! One time it catches the errors and executes the code in the sub and sometimes the browser just displays a standard error page(asp default...
1
1503
by: Tan Hong Giap | last post by:
HI, Does any one has a better ideal of handling error with try..catch for the following scenario. 1. the process could cause many kinds of error. which means the nested try..catch may happen. 2. Regardless of error occor or not, the process hould end up to release memory by setting the object variables to nothing. 3. the process of method is in class of some kind of dll. So, when system
10
2847
by: k.jayachandran | last post by:
I have a very curious and unique problem here. I'm creating a parser using bison and flex. i did all the development work in a linux environment. the project includes the source files output from flex and bison, then several cpp files to create a data structure from the parser. i used gcc as the compiler for the flex output(as it is a c file) and g++ as the compiler for the remaining source files. linked all the object files to create the...
1
1134
by: praveengaur | last post by:
i have made a static "validation" class for handling error , when i press a button then it makes a call to a specific function of validation class , i am getting the custom error message thru throw new exception but now i want to set focus to control for which i generate a error then , then how i can do this. mean i can i get object information which generates a error.
6
2056
doma23
by: doma23 | last post by:
Error number: -214217887 Description: Das Feld ist zu klein fur die Datenmenge, die Sie hinzufungen wollten. Versuchen Sie, weniger Daten einzufugen. Hi, I've made a particular tool by using Access 2003. With all the computers in my office everything works fine. I've started testing phase with a colleague in Germany that will need to use the tool as well. However, when she tries to save some data by clicking on SAVE button, she keeps...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10151
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.