Is there a way to cancel a form's close event? If a user clicks the form's close button, I want a msgbox to ask if they are sure, and if yes continue and close, else cancel the forms close event. I know how to perform the msgbox and the if statement. I can not figure out how to cancel the form's close event.
I have the following code on a report's Activate event:
Code:Private Sub Report_Activate() If Me.HasData = True Then DoCmd.Maximize DoCmd.ShowToolbar "ReportOnly", acToolbarYes Else MsgBox "No records found for criteria selected.", vbExclamation, "No Data" DoCmd.close acReport, Me.Name End If End Sub
Which works as expect. However, the code below is used to number the pages of the report based on group and is still being triggered:
Code: Private Sub PageFooter_Format(Cancel As Integer, FormatCount As Integer) 'On Error GoTo PageFooter_Error
Dim i As Integer If Me.Pages = 0 Then ReDim Preserve GrpArrayPage(Me.Page + 1) ReDim Preserve GrpArrayPages(Me.Page + 1) GrpNameCurrent = Me!TechName If GrpNameCurrent = GrpNamePrevious Then GrpArrayPage(Me.Page) = GrpArrayPage(Me.Page - 1) + 1 GrpPages = GrpArrayPage(Me.Page) For i = Me.Page - ((GrpPages) - 1) To Me.Page GrpArrayPages(i) = GrpPages Next i Else GrpPage = 1 GrpArrayPage(Me.Page) = GrpPage GrpArrayPages(Me.Page) = GrpPage End If Else Me.txtGrpPages = "Page " & GrpArrayPage(Me.Page) & " of " & GrpArrayPages(Me.Page) End If GrpNamePrevious = GrpNameCurrent
'Exit_PageFooter_Error: 'Exit Sub
'PageFooter_Error: 'If Err.Number = 9 Then ' Resume Exit_PageFooter_Error ' Else ' MsgBox Err.Number & " - " & Err.Description ' Resume Exit_PageFooter_Error 'End If End Sub
I get a message box stating "This Action can't be carried out while processing a form or report event". Then then it errors on GrpNameCurrent = Me!TechName stating You entered an expression that has no value".
I have a timeclock that I built into my access program. That just allows employees to clockin and out. I needed to ask how to automatically through VBA when a form is closed from a click of the [X] in the upper right hand corner how to cancel the changes that are waiting to be updated in the DB. This is the code I have so far, but this is more for the button I have in my form the "clockin button" that updates the record with the information. I want to be able to allow the person to hit the X and exit the form with no prompts and no updates. This is the code I have so far.
So what I am hoping for is a code that cancels the update from the exit or close trigger that skips the beforeupdate trigger all together. Any suggestions?
Code: Option Compare Database
Dim LTotal As Long
Private Sub Command15_Click()
Private Sub Form_BeforeUpdate(Cancel As Integer)
LTotal = DCount("emp_id", "employee clockin Query", "emp_id = " & emp_id & "") ' if 1+ already clocked in
If LTotal > 0 Then MsgBox "You have not Clocked Out " & emp_first & "", _ vbExclamation, "Please ClockOut." Cancel = True Exit Sub End If
lngAnswr = MsgBox("Is your Entry Correct " & emp_first & "?", vbOKCancel + vbQuestion) If lngAnswr = vbOK Then Cancel = False MsgBox ("ClockIn Confirmed " & emp_first & "") Else ' User chose No. Cancel = True MsgBox ("ClockIn Canceled " & emp_first & "") End If
I am clicking on the cmdReturnToMain button on forms!Wave1Select. It executes the module below, sets frmMain to visible. But before doing so, if you step through it, this sub_Form_Activate() on frmMain runs TWICE after the line Forms!frmMain.Visible = True. Then on the DoCmd.Close line, the database quits, leaving Access open, but the database is now closed. There is no database window and no code in the debugger. Everything is just blank. Very strange and inconsistent. I have tried a compact and repair. Sometimes instead of closing everything out, if I click the close button on Wave1Select, it evidently closes frmMain and re-activates form Wave1Select. Then, if you click it again, it gives you an error because the frmMain is already closed.
Code:'This is code on frmMain Private Sub Form_Activate() If Len(strUser) = 0 Then SetUser End Sub
'This is code on frmWave1Select Private Sub cmdReturnToMain_Click() Forms!frmMain.Visible = True DoCmd.Close End Sub
'Sometimes it runs this code and reactivates the form I am closing after the DoCmd.Close
Private Sub Form_Activate() cboWave1Select = "" Me.SelectionCriteriaOption = 1 Me.Requery End Sub Hopefully, someone will have some ideas. Thank you.
I have docmd.sendobject that opens Outlook to send an email, etc. However if the user does not send the email and cancels out of the message Access is asking the user if they want to debug. How can I simply have Access return to where the user was before they hit the command button that launched Outlook. I don't want them to go into the code. In fact I don't even want a message of any type - I thought I could trap the cancel somehow and code for it...
When setting the cancel property to True in a checkbox's beforeupdate event the form appears to be locked down until you hit the esc key.
To reproduce the problem create an empty form with a textbox and a checkbox, in the checkbox's beforeupdate event add "cancel = true", now whenever you click the checkbox the form (everything except the checkbox) will lockup until you hit the escape key.
When debugging the problem it would appear that when the cancel property is set to true, the checkbox's beforeupdate event gets called whenever you click on any other control. I'm not sure why the checkbox's beforeupdate even gets called isntead of the control that you actually clicked on.
OK, maybe a serious lack of sleep is preventing me from figuring this out or something, i could swear I have done this before. I am trying to use the NoData Event of a report to:
1. Open a small form that informs the user no records exisit for the selection 2. Keep the report from opening in preview mode.
I tried doing a DoCmd.CancelEvent which doesn't work. I tried closing the form using the OnOpen event of the form that opens(the forms opens the way it should). Any method I use to close the report has had no avail.
Where am I going wrong? I realize I could probably do a record count on my form where the print button is, but I just seem to remember doing this all before with the NoData event.
I used the following code in the on close event of my form and it works when the value of [maingameformation.playid] is not previously entered but if there is already a value there it won't overide it? Is this possible to do?
Private Sub Form_Close() [Forms]![gameentryfrm]![maingameformation.playid] = Me.playid End Sub
Hi all - Having a problem getting my macro to run with the ON CLOSE event of a form. Before users exit the form (or database completely), I want the macro to run. The macro is designed to run an update query that updates 3 fields in my main table. Right now, the macro runs and but it only updates 2 of the 3 fields. It's as if the database closes before the update query gets a chance to finish. Any ideas on this?
I am using the following dialog box to ask whether or not the user wants to print the report in the Close event of a report. I really need help finishing the code. As the user presses "X" to close the report, I would it to be that if the user says yes...the report prints. If the user says no...the report closes.:cool:
Private Sub Report_Close() Dim Msg, Style, Title, Help, Ctxt, Response, MyString Msg = "Print the Report?" Style = vbYesNo + vbQuestion Title = "Report" Help = "DEMO.HLP" Ctxt = 5000 Response = MsgBox(Msg, Style, Title, Help, Ctxt) If Response = vbYes Then
I use a macro to enable importing of data into Access. Since this is a built-in command (sorry if I've posted in the wrong forum), I want to trap for the case where user clicks 'Cancel' at any time during the import process.
the code is: DoCmd.RunMacro "mImportTable" ---- mImportTable has "Runcommand Import" as only entry If Not Cancel Then .... <process file and other data checking logic> endif
during testing, I choose Cancel (at various points during the importing), but the system drops into the "Not Cancel" branch of code.
I used this same technique in another Access database without issue ...
Perplexed ... Any clues/help is greatly appreciated. thanks, Carole.
I have a report that I use 'Total Access Emailer' to email to staff. I have two buttons, one to email each staff members contract, and one to preview the report, before printing. Both work well and I have no problems with them.
However....... I thought about adding a msgbox to the close event of the report, so that after previewing and/or printing, they would get the option to email the report/s also.
Dim Msg, Style, Title, Help, Ctxt, Response, MyString Dim UpdateSQL As String
Msg = "Click *YES* to send as email?" _ & Chr(13) _ & "Click *NO*, to NOT send email." _ Style = vbYesNo + vbDefaultButton2 Title = "Email Options..." Help = "" Ctxt = 1000
Response = MsgBox(Msg, Style, Title, Help, Ctxt) If Response = vbYes Then ' User chose Yes. MyString = "Yes" ' Run Emailer Function and email report. Dim strError As String strError = TotalAccessEmailer(1, False, "Form", "", True, True) ' exit to UpdateSQL Else ' User chose No. MyString = "No" ' exit to UpdateSQL. End If
Now I get the message box, with my two options. I select no, and the routine runs the 'UpdateSQL' and exits, all ok.
However...if I select 'yes', the emails fail to send, and the report opens in design view.????
My gut feeling is that the 'UpdateSQL' is running before the email function has a chance to complete. The email function/query being almost and identical version of the SQL above, apart from being a grouped select query. Thereby, when the email function comes to select its data to use, the above query, has removed the data that the emailer would need to use.
Can anyone tell me if I'm in the ball park with this idea? And if so, is there a way around this?
Would it be best to run the update query on the 'form active event' and requery, when the report has closed?
I'm not sure the best way to do this? Help please???
I'm looking for a way to cancel the closing of a form/app. I added a button asking if the user is sure they wish to exit, and am having difficulty finding the correct code to cancel the close event.Here is my codeDim ians As Integer ians = MsgBox("Are you sure you wish to exit?", vbYesNo, "Exit App") If ians = vbNo Then DoCmd.CancelEvent DoCmd.OpenForm "orderlist", acNormal Exit Sub End IfCan help or send me down the right path?Thanks
Hi all, I have a textbox with an input mask for an id number, so if I begin adding numbers I get an error message if they're not in correct format- this is fine- but I want the user to be able to cancel the entry and exit the form, but when I click the cancel button I get an error message about the id format- anyone know how I can allow cancel to override this? thanx
Hi I have a form with avout 4 fields based upon a query to allow user to edit an entry if needed. I want to put a cancel button on so that if they change their mind after having changed a field it reverts to its original value - so for instance they decide to change a land line phone number to a mobile, exit the field but then have a brain storm and decide not to do this so hit the cancel button. At the moment my cancel button just closes the form (and accepts the overwrite) which would be fine if I am using ADO but not if I am using a bound form. I am sure there is a simple answer (since I cannot be the only person who thinks this option might be a good idea). I am just not sure how to look for it. Any thoughts or ideas? Thanks
I have a pop up form that requires me to fill out all 4 fields of the form. When I don't, I get a prompt telling me which field(s) I've forgotton to fill in and allows me the option to Cancel (Yes or No) and if i decide yes it wont save and will close the form. BUT when I say No (Don't cancel), it still closes out the form and I obviously don't want that. I don't know if it might have to do with my macro button either? Any clue?
Thanks in Advance!
Private Sub Form_BeforeUpdate(Cancel As Integer) Dim blnError As Boolean Dim strError As String
strError = "You are missing data for "
If IsNull(Me.[Account Number]) Or Me.[Account Number] = "" Then blnError = True strError = strError & "Account Number," End If
If IsNull(Me.Contact) Or Me.Contact = "" Then blnError = True strError = strError & " Contact," End If
If IsNull(Me.Department) Or Me.Department = "" Then blnError = True strError = strError & " Department," End If
If IsNull(Me.Address) Or Me.Address = "" Then blnError = True strError = strError & " Address," End If
If blnError Then strError = Left(strError, Len(strError) - 1) If MsgBox(strError & vbCrLf & "Are you sure you want to cancel." & vbCrLf & "If you do, the info will not be added.", vbQuestion + vbYesNo, "Close Confirmation") = vbNo Then Cancel = True End If End If End Sub
Hi guys. I got a unbounded form that is used to update/delete/add records. It also has navigation buttons called next and previous. I have the following problem and do not know how to fix it. I be happy if some one help me fix them. Thanks
http://i5.photobucket.com/albums/y180/method007/editform.jpg ===> Picture of unbounded form 1) When I press add button and if I try not to add and press cancel. The old value does not get posted back into text box! But if I click on edit button and try not edit and press cancel button the old value get posted. I want the old values get posted to text box when a user presses cancel after he clicked on add button.
2) When I click on edit or add button then if I press next it tells me to either save or cancel. When I press on cancel button and then press next again. I get same prompt asking me to either save or cancel again!
Code:Option Compare DatabaseOption ExplicitSub clearTextBoxes()''clearing the tow texboxes txtCompanyName and txtCustomerIdMe.customerNumber.Value = ""Me.customerName.Value = ""End SubSub getReadyForAnAddOperation()Me.cmdSave__.Enabled = TrueMe.cmdSave__.SetFocusMe.cmdCancel.Enabled = TrueMe.cmdAdd__.Enabled = FalseMe.cmdEdit.Enabled = FalseMe.cmdDelete.Enabled = FalseEnd SubSub stateOnLoad()Me.customerName.SetFocusMe.cmdCancel.Enabled = TrueMe.cmdSave__.Enabled = FalseMe.cmdEdit.Enabled = TrueMe.cmdAdd__.Enabled = True'''disableing the cancel and save button on load'''Me.cmdCancel.Enabled = False'''Me.cmdSave__.Enabled = FalseEnd Sub'declaring subrotineSub FillFeilds()Me.customerNumber = myRS.Fields("customerno")Me.customerName = myRS.Fields("customername")End SubPrivate Sub cmdAdd___Click()clearTextBoxesgetReadyForAnAddOperationpbAddingARecord = True'''changing the value of this boolean variablemyRS.AddNewEnd SubPrivate Sub cmdCancel_Click()FillFeildsstateOnLoadEnd SubPrivate Sub cmdDelete_Click()Dim x As Variantx = MsgBox(" You are abut to delete " & Me.customerName & " from this table - proceed ? ", vbOKCancel)If x = 1 ThenWith myRS.Delete.MoveFirstFillFeildsstateOnLoadEnd WithEnd IfEnd SubPrivate Sub cmdEdit_Click()''clearTextBoxesgetReadyForAnAddOperationpbEditingARecord = True'''changing the value of this boolean variableEnd SubPrivate Sub cmdMoveFirst_Click()myRS.MoveFirstFillFeildsEnd SubPrivate Sub cmdMoveLast_Click()myRS.MoveLastFillFeildsEnd SubPrivate Sub cmdMoveNext_Click()If pbAddingARecord = True Or pbEditingARecord = True ThenMsgBox ("Please save or cancel changes first ")Exit SubEnd IfmyRS.MoveNextIf myRS.EOF ThenMsgBox ("Last Record")myRS.MovePreviousEnd IfFillFeildsEnd SubPrivate Sub cmdMovePreviouse_Click()myRS.MovePreviousIf myRS.BOF ThenMsgBox (" First record")myRS.MoveNextEnd IfFillFeildsEnd SubPrivate Sub cmdSave___Click()If pbAddingARecord = True ThenmyRS.AddNewEnd IfIf pbEditingARecord = True ThenmyRS.EditEnd If'''inserting the value of textboxes to the table fields.feeding the date to record setmyRS.Fields("customerno").Value = Me.customerNumber.ValuemyRS.Fields("customername").Value = Me.customerName.Value'''calling update method. it comittes the changesmyRS.UpdatepbAddingARecord = FalsepbEditingARecord = FalsestateOnLoadEnd SubPrivate Sub Form_Load()Set db = CurrentDb()'''Set myRS = db.OpenRecordset("select * from customer")Set myRS = db.OpenRecordset("customer", dbOpenTable)''' need to learn how to add index to customer table'''myRS.Index = ("Company Name")'calling subroutinestateOnLoadFillFeildsEnd SubPrivate Sub lblFindIt_Click()With myRSSelect Case Me.lblFindIt.CaptionCase "Company Name"Me.lblFindIt.Caption = " First Name "''' this indexcontactfirstname should already exist in the table''' you can also create index trough code on tables. this method''' not good in multi user evironment . best way to create indexes and''' refere them trough code.Index = "CotactFirstName"Case "First Name"Me.lblFindIt.Caption = " Last Name ".Index = "CotactLastName"Case "Last Name "Me.lblFindIt.Caption = "Company Name ".Index = "CompanyName"End SelectEnd WithEndEnd SubPrivate Sub textFindIt_Change()Dim strSeek As VariantDim posInmyRS As Variant''' feeding it the value from text boxstrSeek = Me![textFindIt].TextWith myRSposInmyRS = myRS.Bookmark.Seek ">=", strSeekIf .NoMatch = True ThenmyRS.Bookmark = posInmyRSExit SubEnd IfFillFeilds End With End Sub
my modul code Code:Option Compare DatabaseOption Explicit'''we declare publick variable in the module'''note we can oly declare public ariables insdie module'''not inside the function''' we declare it here so that fillfeilds sub routine can see it.''' we can not declare it public inside onloadPublic db As DatabasePublic myRS As RecordsetPublic pbEditingARecord As BooleanPublic frmName As StringPublic ctrlName As StringPublic pbAddingARecord As BooleanPublic pbCurrentPos As Variant
I have a form that is used to view data as well as add a new record. From a main menu I have an option that has a button call add new record. this button puts the form into a data entry mode. However when I try to exit I get an error that says I can't leave the primary key null. I am not leaving it null but I am trying to cancel the new record transaction. What do i need to do to cancel the new record entry? I was using the following command Code: DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70 which is the built in undo commmand into access. But if there is no record than you can't undo and i keep getting errors.
as the form opens with the access application window hidden, and I found that the .ldb file didn't close if I simply used the X.
I have a series of fields with validation rules which activate on exit. One of these validation rules is in the box which gets focus when the form opens. This means that I get the validation text error message boxes when I close the form with the X.
If I have started to complete the form, I get a whole host of error messages and validation messages when I try to shut it with the X.
Is there a way of closing the form and cancelling or ignoring all error message boxes. I want the user to be able to close the form if they have decided not to fill it in after all, or have got part way through and want to cancel.
I would really appreciate any help, I am sure this is a very basic question and I should probably be able to find the answer, but I can't and I am very fed up!
I am attempting to use the 'Inventory' button on the 'IncidentFrm' to save the current record, close the form and then open the InventoryFrm.
My stumbling point is that I want the InventoryFrm to open with the IncidentID FK that was being edited when the IncidentsFrm was open. I've tried macros, I'm able to close the form, but it comes up with an error when opening the InventoryFrm. The macro was opening the InventoryFrm with a filter, based on a query where I was simply attempting to pull the MAX of all IncidentID. I truly want it to just copy the IncidentID and apply to the form that is opening.
Am I going about this completely wrong, or just not applying the specifics?
I have a command button that opens a new form. I want to make this command button close the current form in addition. I'm guessing that there is some code that can be added to execute this command? Does anyone know what needs to be done in order to do this? Thanks.
I have a form, Customer Orders that runs an event procedure for updating inventory status of out of stock items when the control is double clicked. I would like to place that same procedure in another form for Purchase Orders when an update is preformed.
My goal is to automate updating the Customer Orders form double click to remove the step of opening a second form and double clicking on each item that was added to inventory when they were just added to inventory from the Purchase Order.
Is there a way to take the code from the event procedure on one form, paste it into the event procedure for another form and have it point back to and modify the first form?
I've a custom menu bar from which I can choose any of my forms. However when you choose a new form the old form stays open, sloppy in my mind. Is there any way i can choose the new form from the menu bar & close the previous form? I've tried to close on deactivate, w/ no luck.
When the user clicks to close the form the Before Update event runs, and has the following code to check that all the required fields are completed:
If IsNull(Me.ToxReceived) Then stdresponse = (MsgBox("You must enter the toxicology received date before continuing." & Chr(13) & Chr(10) & Chr(13) & Chr(10) & _ "Do you want to do that now? Click YES to return to complete the form, click NO to undo the record", vbYesNo, "Missing Data"))
If stdresponse = vbYes Then Me.ToxReceived.SetFocus
Else Cancel = True Me.Undo Exit Sub End If End If
If the user clicks no, and the record is undone, how do I get the close form event to still continue?