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
5 1757
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: -
Private Sub cmdEditAcct_Click()
-
Dim Title As String
-
Dim Msg As String
-
-
If IsNull(Me.AllAccountsListbox) Then
-
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
-
Me.AllAccountsListbox.SetFocus
-
Else
-
DoCmd.RunMacro "mcrEditAcct" 'open form
-
[Forms]![fdlgEditAccount]![txtUsername] = [Forms]![frmEdit]![txtUsername]
-
End If
-
End sub
Linq ;0)>
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!
In addition, it open a blank form with the error 2448.
thanks!
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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...
| |