I posted this question about an hour ago but I seem to have been logged out by the time that I actually pressed "send", so I don't know whether it was posted correctly - I can't find it!
I've created four buttons on a form to negotiate my way through the records. When I come to the end, a message box is shown stating that the next record cannot be found (it doesn't exist). Can I trap this message and use it to activate some code? I thought about a form popping up (in "corporate" colours to match the remainder of the database) or a form asking whether I want to add another record.
I looked at the code that Access generated when I made the buttons, and I saw the following:
I "remmed" out the middle line, but the automatic message box still appeared. I added a line of code: <MsgBox Err.Number>, but that didn't give a result, so I guess that the message box that's being shown isn't generated via this snippet of code.
I know that I could disable the relevant button when the record number reaches the end or add another button to add a new record, but I'd like to trap this automatic message box. Can I do so, and, if so, how?
Hi, I have a button in a form that loads a report, if there is no data in the report then 2 error messages are displayed, however as these messages have no affect and they do no harm as such I would like to prevent them from being displayed. The error messages are error 91 “invalid use of isnull” error and error 2501 “cancel event error message”
I’ve been able to prevent either error 91 from being displayed or alternatively 2501 using a single if statement but not both of them together using two if statements.
(If error 94 is displayed, I would still like the report to open, error 2501 is displayed after the report is closed if there’s no data & i just want this message not to be shown)
Any ideas what im doing wrong? :confused: any help much appreciated
Regards
Kevin
Below code works ok (to trap just the one error message):
Err_cmdPreview_Click: If Err.Number = 2501 Then ' ignore cancel event error Else MsgBox Err.Number & " - " & Err.Description End If Resume Exit_cmdPreview_Click
End Sub
But the below code here doesn’t work (when I use 2 if statements to try & trap both of the error messages)
Err_cmdPreview_Click: If Err.Number = 94 Then ' ignore isnull error DoCmd.OpenReport stDocName, acNormal
Else If Err.Number = 2501 Then ' ignore cancel event error Else MsgBox Err.Number & " - " & Err.Description End If
Is there a way to over-ride the message box which is automatically generated when you use the Wizard button to create command buttons?
ie. When you create a button through the wizard to delete a record it says "You are deleting one record" is there a way to override that message and put another one
i look at the code but I cannot see where the message part is inputted.
I realise that i can probably write the code long hand but (always) looking for a quicker way.
This is probably very simple, but how and where do I add codes to the button where a confirmation message pops up? Like, "Are you sure you want to save?" or "Are you sure you want to exit?"
For Example: Save and Close button
Private Sub cmdClose_Click() On Error GoTo Err_cmdClose_Click
I have a command button with the VBA code below. I'd like a message box to appear with a comment and an "OK" button that continues the code below . . is this possible?
Private Sub cmdDuplicateOverpayments_Click() On Error GoTo Err_cmdDuplicateOverpayments_Click Dim stDocName As String
I have a "Browse" button on a form that works fine. I would like to add a Message Box that warns the user that if they click "ok" on the message box they will start browsing, and if they dont want to do that click "cancel" in the message box. ( I know its obvious, bu thats what my friend wants). Is there an easy way to do this?
I use a close button to close a form. There is list box in this Form. If the list box is empty, then simly close the form. However, if there are projects in the list box, I want to give a warning. If the user say YES, then everything in the listbox will be deleted and the form will be closed. If user say NO, tehn the form will not be closed. They then can use anotehr button to save teh projects.
I wrote the follwing code. The delete portion itself works. But it seesm comfused with msgbox. Could you pelase help me correct this code? Thank you very much for your help.
lbDestination -- list box name
Private Sub Close_Click() On Error GoTo Err_Close_Click
If IsNull(Me.lbDestination) Then DoCmd.Close Exit Sub End If
If MsgBox("You have unsaved initiatives. Are you sure you want to close?", vbQuestion + vbYesNo + vbDefaultButton2, _ "Delete?") = vbYes Then
Dim rsDestination As DAO.Recordset Set rsDestination = CurrentDb.OpenRecordset("tbInit", dbOpenDynaset)
rsDestination.MoveFirst Do While Not rsDestination.EOF
I have created command buttons to enter event registration information after biographical information has been completed. When I click on the button I get the following error message:
"Microsoft Office Access cannot find the field '|' referred to in your expression."
This is the On Click code that I have in there. Can anyone spot the error of my ways?
Private Sub RegisterButton_Click() On Error GoTo Err_RegisterButton_Click If IsNull(Me![AttendeeID]) Then MsgBox "Enter attendee information before registering for an event." Else DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 DoCmd.OpenForm "Registration", , , "[Registration]![RegistrationID]=Forms![Attendees]![Attendees Subform].form![RegistrationID]" End If
Exit_RegisterButton_Click: Exit Sub
Err_RegisterButton_Click: MsgBox Err.Description Resume Exit_RegisterButton_Click End Sub
I am not sure where to start or go about creating message box that would display "No results found" if my queries return no results. My search of the forums hasn't been fruitful.
I have created one form that has a text box and a button that works as a search function to run through the tables and displays the applicable queries. Currently, if no results are returned nothing happens. Preferably I would like a message box to display stating that there were "No results found". I would assume that the code would be associated with the "Find" button. Here is the VBA code as it stands, again, I haven't even attempted to add code for a message box.
Private Sub Find_Click() On Error GoTo Find_Click_Err
If DCount("Heading", "Service Desk Manual Query") > 0 Then DoCmd.OpenQuery "Service Desk Manual Query", acViewNormal, acReadOnly End If
I'm using Pat Hartman's code to select items from a list box and then append the records to a table. If a user doesn't select anything before clicking the buttom I'm trying to give them an error message. I've tried it in various places but can't get it to work. The attached is giving me the error message regardless of whether they have selected anything or not.
On Error GoTo Err_CreateAttendanceRecords_Click
Dim i As Variant Dim dbs As DAO.Database Dim rst As DAO.Recordset Dim qd As DAO.QueryDef
Set dbs = CurrentDb Set qd = dbs.QueryDefs!qrynewvaluations2 Set rst = qd.OpenRecordset
If i = 0 Then MsgBox "You must select at least one property before continuing" Exit Function End If
Next i Set rst = Nothing Set qd = Nothing MsgBox "Records Created"
exit_createattendancerecords_Click: Exit Function
Err_CreateAttendanceRecords_Click: Select Case Err.Number Case 3022 'ignore duplicate keys Resume Next Case Else MsgBox Err.Number & "-" & Err.Description Resume exit_createattendancerecords_Click End Select
If you open the attached sample you will see what my problem is.
I have Form /Subform with look up combo that will not allow duplicate entries in same subform record. This works fine, access displays an error when a duplicate has been added as it should. What I want to do is trap that error myself and display a msgbox that will allow the entry to undo (the msgbox undo etc I can handle, it the trapping of the error)
I need a way at preventing users from using the scroll funtion on mouses from creating a multitude of balnk records and hence was looking at ghudson better mouse trap as a way of doing this... this is the way forward isnt it?
Looking at the code it starts with... 'For those of us not using Access XP, we have a challenge to prevent 'our users from advancing to another record if they do not use the controls 'we want them to use or to prevent them from bypassing our validation 'procedures too ensure the current record is okay to be saved.
How do you prevent this from happening in Access XP?? Access XP = 2002 does it not?
First off sorry about the really bad layout…..I don’t know how to do all the fancy stuff but really wanted to share this because it seams like a lot of people wanted help with this.
So here is what I have going on.
I have a form to add a record, and I have a number of fields, then an “Add Record” button and a “Cancel Record” Button. What I wanted to do was:
A: Stop the form from going to another “New Record Form” when moving the mouse wheel B: Stop the form from going to another “New Record Form” when pressing the “Tab” key
Here is what you got to do to solve the mouse problem:
1.) Create a field in the form that has the Name “MouseWheel Move”, and set the “Visible” property to “No” 2.) Enter the Fallowing: Private Sub Form_Load() Me![MouseWheel Move] = "No" End Sub 3.) Enter The Fallowing: Private Sub Form_MouseWheel(ByVal Page As Boolean, ByVal Count As Long) Me![MouseWheel Move] = "Yes"End Sub 4.) Enter The Fallowing: Private Sub Form_BeforeUpdate(Cancel As Integer) If Me![MouseWheel Move] = "Yes" Then DoCmd.CancelEvent Me![MouseWheel Move] = "No" End If End Sub
Here is what you got to do to solve the Tab problem:
The last item on my form is my “Cancel” button; so when the focus is on my “Cancel” button (ie. the last item on the form) and I press tab I want the focus to go to the first field on my form.
Private Sub Cancel_Button_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 9 Then Me![Field Name for the First Item on the Form].SetFocus End If End Sub
One more thing, I am using Microsoft Access 2002 (10.6771.6735) SP3 and it works fine
I have a form with 22 data fields. There are 4 entry flow paths. (1) is 1 to 9, 10, 20 to 22 (2) is 1 to 9, 11 to 14, 20 to 22 (3) is 1 to 9, 15 to 17, 20 to 22 (4) is 1 to 9, 15 to 17, and stop at 19. If information is in Field 10, then I need to prohibit entry in the other 3 paths. How can I do this?
I know this topic has been covered over and over but I've searched and searched and can't find my answer. I did find one post with a link to a possible answer but the link was broken.
My form has a required field. When a user attempts to X out of the form I have code in the Before Update event that checks this field and if it is blank:
MsgBox "Payment Terms must be filled in before closing the form" Me.PaymentTerms.SetFocus Cancel = True
The message box appears, but then the
You can't save this record at this time...blah blah blah.....
dialog appears and then the form closes.
How can I prevent the user from closing the form if this field is blank? It seems like once the X is clicked there is no turning back. I realize that I could remove the close button (X) from the form and use a command button instead but this may only mess up the users who have been using this DB for years. Is there any way to go backward once the close button has been clicked?
1.i trapped error 3314 and other errors at my custm buttons(save,edit...) but... at my 2 forms(one single and the other continuous, access gives me an error about an empty field in a table (primary id), when i press tab (it moves to next record). The same action has my continuous form when i click at an empty field at next record or pressing tab with empty values at primary fields.
What can i do to post my own messages?
2. I have a text box (a) that takes value form an other text box (b): b=2*a. both text boxes send values to a table How can i prevent user from chanching the value on (b) text box?
thanks in advance Dimitris Greece (sorry for my bad english)
How do I programmatically force an error dialog to make a certain choice?
I'm able to trap the dialog via the following code:
Private Sub Form_Error(DataErr As Integer, Response As Integer) If DataErr = 7787 Then 'record updated by another "user" (subform) MsgBox "Error trapped!" Response = acDataErrContinue Else Response = acDataErrDisplay End If End Sub
Problem is, if I bypass the 7787 error in this manner, it defaults to dropping the changes, rather than saving the record, which is what I want. (Both are choices on the dialog.)
i am using access against an Oracle DB through an ODBC driver, and when appending records to a local table, if access gets an Oracle record error "#deleted", the append query aborts. . . that's fine, but I can't figure out how to trap the error to get the rest of the records. . .
Hi guys . i wonder how i can trap the following errors in access 2000 forms. I have the database tables in sql server 2000 and front end is made by access 2000 forms. I be happy if some one show me how i can trap these errors and promt aproperte message to the user when they violate them using forms.Thanks
1)Violation of not null constraint 2)primary key violation 3)Trigger violation 4)and other erros
I'm using GHudson's A Better Mouse Trap code. It works great. However, I added other code from http://www.databasedev.co.uk/image-form.html to get and save the path to image files and now I think there is a conflict between the sets of code.
The Images tab on the form frm_CreateNewSpec is where I have problems. The error messages are definitely from Mouse Trap...I just don't know how to resolve the problem.
I've probably missed something simple, but don't know what.
Any and all assistance is greatly appreciated by this novice.
I have a form which has a button to email the data out in a standard email message.
Private Sub Command60_Click() Dim MyDb As dao.Database Dim rsEmail As dao.Recordset Dim sToName As String Dim sSubject As String Dim sMessageBody As String
[code]...
This works well enough, however, FIELDS 11 through to 16 contain the venue address. This is all we ll and good if every field of the venue address is populated. here are times when not all of the fields are populated, for instance, the address might only be 5 lines.I know I can do this using IIf statements on a report, but how can i achieve the same thing for the email.
I am importing .txt files into Access table via VBA code (i.e., not via Saved Import Spec). Is there a way to trap the error if a particular field does not get imported due to incorrect format? When you import via Saved Import Spec and there are errors in formatting, Access generates an 'ImportErrors' table, which tells you which fields could not be updated.
Is there a way to generate a similar 'ImportErrors' table with VBA error checking?