I'm building a front end for an Access database. My users don't want or need to see the "You about to insert X records" sort of messages that come up when you run an INSERT, UPDATE or DELETE query.
The only way I've been able to find to turn these messages off programtically is DoCmd.SetWarnings False in VBA and then turning them on afterwards. However, this disables all warnings, and if the code errors before the DoCmd.SetWarnings True command, then they stay off, which can be anything from a nuisance to dangerous.
Is there any way of supressing only the SQL warnings in Access and leaving others (e.g. the "do you want to save this query" messages) intact?
Run "action queries" with Database.Execute or QueryDef.Execute instead of DoCmd.RunSQL.
The .Execute methods do not trigger those confirmation messages, so no motivation to use SetWarnings False to suppress them.
There is also this alternative, for those not wanting to write code
In Access Options > Advanced > Uncheck the required confirmation for the desired fields.
Related
I know how to use the DLookup function, I know how to use the onclose event on reports as I use both extensively. However, I can't seem to get them to work together. With the help of Stackoverflow and some google, I can get all my questions answered. So, I am back!
This is my code. When I close a specific report, other forms will open, exports happen, etc. I won't bore you with the code for all that, I just can't figure out how to have an If statement based on a value in a table...and NOT get an error message.
Private Sub Report_Close()
If DLookup("Design Mode", "Database_Settings").Value = True Then
MsgBox "True"
Else
MsgBox "False"
End If
End Sub
This is a Yes/ No field I am referencing.
Jist...If the field is checked, true, do all the exporting and stuff. (Normal Operations). If the field is not checked, false, then just close the report. (When I use it). All the actions that run, have been working for a while now. I get an error message now since I added a referenced field from a table.
Thanks -j
Try this:
If Nz(DLookup("[Design Mode]", "[Database_Settings]"), False) Then
I was wondering if anyone knew how to create a custom message for the save record confirmation, only using macros and not user coded VBA. I've done this for a previous project in VBA but this time I'm trying to only use Access' macro builder. I'm using Access 2010 to build this project.
So far I've got
IF 6=MsgBox("Are you sure you want to delete this customer's information? WARNING, this is unrecoverable."),52 Then
RunMenuCommand DeleteRecord
MessageBox Message "Customer information deleted."
This makes a yes no dialog box first as the confirmation but it then shows the built-in confirmation that Access bundles with the DeleteRecord command.
Thanks,
Jake.
don't use the run menu command. You could for example delete using SQL
currentdb.execute "DELETE * FROM myTable WHERE myTableId=" & idOfRecordToBeDeleted
Looking for a similar solution myself and after much ado, have a solution. Using Access2013, but should be the same logic.
In my case, I wanted a Yes/No message box to add a record on Yes, and reload the form on No. In your case, leaving out the filters and values, it would be simpler... If yes, RunMenuCommand = Delete Record Else StopMacro. You could set up the specifics for No, but Else handles it for me.
Specifics: I have a form with a combo box (macro is tied to the combo box/After Update property) to select and filter the records. If there is a matching record(s), display it(them). If there is no matching record, display a message (no records) and prompt the user to add one (yes) or not (no).
The entire macro.... (no VB)
ApplyFilter
Filter Name (blank)
Where Condition =="[cID]= "& Str(Nz([Screen].[ActiveControl],0))
Control Name (blank)
If IsNull(eID]) Then
If MsgBox("No record",4,"Nothing found")=6 Then
SetProperty
Control Name cID
Property Value
Value =Str(Nz([Screen].[ActiveControl],0))
StopMacro
Else
RunMenuCommand
Command RemoveAllFilters
StopMacro
End If
End If
I have a table in MS-Access - let's call it tComputers. Two of the fields in that table are titled Status - with the options of Active, Storage, Deactivated - and DeactivationDate.
If I wanted to make DeactivationDate mandatory if and only if the value of Status is Deactivated, how can I do that?
If I wanted to make DeactivationDate mandatory if and only if the value of status is Deactivated how can I do that?
Conversely, if a Deactivated record later changes Status ... say becomes Active ... should the DeactivationDate be discarded?
I think you can accomplish this with a table level Validation Rule. With tComputers in Design View, open the property sheet and use this as the Validation Rule property:
IsNull([DeactivationDate])=IIf([Status]="Deactivated",False,True)
Figure out what message you want the users to see when that validation rule is violated and put it in as the Validation Text property. It's unlikely the default message would mean anything to them.
Although it's possible, I doubt know how useful this is. The users should be editing data via a form, and that gives you the opportunity to enforce your validation requirements before the database
engine even attempts to save the data ... use the Form_BeforeUpdate event as #mwolfe02 described.
Edit: Here is an outline for Form_BeforeUpdate. It assumes you have a combo named cboStatus bound to the Status field, and a text box named txtRetireDate bound to the RetireDate field.
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
Select Case Me.cboStatus
Case "Deactivated"
If IsNull(Me.txtRetireDate) Then
strMsg = "RetireDate is required for Status = Deactivated"
MsgBox strMsg
Me.txtRetireDate.SetFocus
Cancel = True
End If
Case "Active", "Storage"
'* what should happen here? *'
Case Else
'* what should happen here? *'
End Select
End Sub
If you want to enforce this at the table level I believe you are out of luck. You might be able to do something with Data Macros if you are using Access 2010. EDIT: I stand corrected. Though I personally don't ever use this functionality (preferring to handle the validation at the form level where more complex validation is practical) it is most definitely possible: Validation Rules
If your users will only be updating the data through a bound form, you can perform the validation in the Form_BeforeUpdate event. Then if Status = 'Deactivated' and DeactivationDate is Null, you would set Cancel = True which will prevent the changes from being saved. Obviously you'd want to show a message box or indicate in some other way why the form could not be saved.
If you are entering the data with a form, you could use VBA to validate the form entries. On the button press to save the data you can check to see if the value of status is Deactivated, and if it is, you can require DeactivationDate to have a value. Otherwise, the data won't be saved.
Doing what you want in the table design window, I'm not sure how that could be done.
An MS Access form that has been working for over a year now, does a simple:
"Dim MyQuoteID as INTEGER
MyQuoteID = Me.QuoteID"
(It then proceeds to execute an SQL Statement inserting "MyQuoteID" that it just captured from the form)
...Only now it errors and says "Method or data member not found" on "Me.QuoteID".
Of course, the "QuoteID" box is right there, plainly visible, and has been for over a year.
Obviously some kind of corruption because I didn't change anything - but it doesn't solve with a compact and repair!
WTH??????
Two things to try:
Decompile via the command line (msaccess.exe "path\to\your.mdb" /decompile)
Use the undocumented SaveAsText and LoadFromText methods to "export" and "import" your form
SaveAsText acForm, "YourFormName", "YourFormName.txt"
LoadFromText acForm, "YourFormName", "YourFormName.txt"
I think you meant to write TextBox rather than INT. Assuming that this code is in the VBA module for a form, you do not need to define any of the controls in this way, nor is it good practice to do so. Just delete these two lines, and it might fix your problem.
I am trying to make a small form in MS Access 2003 SP3, I use some function that some other people made and these function has msgbox in it. I would like to disable msgbox while I am running the form. Is it possible in Access to disable msgbox?
I created my finction called msgbox. Seems like its working. Thanks everyone for your help.
Public Function MsgBox(Prompt, Optional Buttons As VbMsgBoxStyle = vbOKOnly, Optional Title, Optional HelpFile, Optional Context) As VbMsgBoxResult
If myProcedureisRunning then
VBA.MsgBox Prompt
else
debug.print prompt
endif
End Function
If in fact these message boxes are produced from VBA code, then comment them out. However, if they are Access generated, such as the message box when inserting or updating records, you need to use the command DoCmd.SetWarnings False in order to suppress them. Just make sure to turn warnings off only when needed, then turn them back on. Otherwise, ALL message boxes from Access will be off, even in "design mode".
Do a CTRL-F and find for MSGBOX and comment it. I guess that's the only way you can do it.
Press Alt+F11 to open the Visual Basic IDE, then press CTRL+F to search. Type msgbox into the find, select "Replace" and type'msgbox into the "replace with" box (note the apostrophe). This will comment out all msgbox statements in the project.