473,326 Members | 2,134 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,326 software developers and data experts.

Handling error

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_Click()
Dim Title As String
Dim Msg As String

On Error GoTo Err_cmdEditAcct_Click

DoCmd.RunMacro "mcrEditAcct" 'open form
[Forms]![fdlgEditAccount]![txtUsername] = [Forms]![frmEdit]![txtUsername]
Exit_cmdEditAcct_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_cmdEditAcct_Click
Case Else
MsgBox Error$
Resume Exit_cmdEditAcct_Click
End Select
End sub
Dec 2 '09 #1
5 1757
missinglinq
3,532 Expert 2GB
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 AllAccountsListbox 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
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
In addition, it open a blank form with the error 2448.
thanks!
Dec 2 '09 #4
missinglinq
3,532 Expert 2GB
If you replaced AllAccountsListbox in the code I gave you with the actual name of your listbox,

DoCmd.RunMacro "mcrEditAcct"

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
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
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...
1
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...
1
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...
3
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...
0
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...
1
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....
10
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...
1
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...
6
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
1
isladogs
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...
0
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...
0
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.