Docmd.RunCommand acCmdFind


I want to call the default Find menu item (just as if the user had clicked the binoculars). That's as simple as pie. What I'd now like to do is change the default options for the user. (The 'Whole Field' default trips up users a lot). Anyone know how to do this?


Sponsored Links:



Hi
I am getting the "No Current Record" on the "DoCmd.RunCommand acCmdDeleteRecord" when I run it the first time, when I run it again it runs without the error message?

This is run just before a Close form CMD

Hope someone can help

Cheers
Gezza




I am trying to get a button to delete the current record using the command:

DoCmd.RunCommand acCmdDeleteRecord

but nothing happens when it runs. I am sure the code is running because I have set a msgbox to come up after it in the click event and it comes up.

If I use the button wizard to create the button it will delete a record, but that seems to break the "lost focus" code I use for the button.

Thank you.

(Access 2010)




I have a form to store records of different types of expenditures, and to update the balances of budget lines in another table. After trial and error I wrote the following code triggered by the form before update event. It allows record navagation without problem, and when a new expenditure amount is added or modified in the open record, and the message box is answered yes, then all works fine. Unfortunately, if any other fields in existing records are modified and I try to answer no to the message box I get an error and prompt to debug. When I use almost anything for the Case vbNo code, I get error messages. In essence I just want to return to the existing open record and simply save the changes to the edited field and move on.

Any help will be greatly appreciated.

Here's the code.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Answer As Integer
Answer = MsgBox("Do you want to save this record and update the balance?", vbQuestion + vbYesNo, "Question")
Select Case Answer
Case vbYes
Dim strSrvTypeHold As String
Dim lngAmtHold As Long
Dim lngRentHold As Long
Dim lngFurnHold As Long
Dim lngSecDHold As Long
Dim lngRehabHold As Long
Dim lngContinHold As Long
'DoCmd.RunCommand acCmdSaveRecord
strSrvTypeHold = Me.[SrvType]
lngAmtHold = Me.[Amount]
DoCmd.OpenForm "frmBalance"
lngRentHold = Forms![frmBalance]![RentStipends]
lngFurnHold = Forms![frmBalance]![FurnitureHoushld]
lngSecDHold = Forms![frmBalance]![SecDeposit]
lngRehabHold = Forms![frmBalance]![Rehab]
lngContinHold = Forms![frmBalance]![Contingency]
If strSrvTypeHold = "Rent" Then
Forms![frmBalance]![RentStipends] = lngRentHold - lngAmtHold
ElseIf strSrvTypeHold = "Contin" Then
Forms![frmBalance]![Contingency] = lngContinHold - lngAmtHold
ElseIf strSrvTypeHold = "FurnHoushld" Then
Forms![frmBalance]![FurnitureHoushld] = lngFurnHold - lngAmtHold
ElseIf strSrvTypeHold = "Rehab" Then
Forms![frmBalance]![Rehab] = lngRehabHold - lngAmtHold
ElseIf strSrvTypeHold = "SecDep" Then
Forms![frmBalance]![SecDeposit] = lngSecDHold - lngAmtHold
End If
Case vbNo
DoCmd.RunCommand acCmdSaveRecord
End Select
End Sub

Thank you in advance for any assistance




Hello gents,
I am struggling since yesterday on this item. I have a Form_BeforeUpdate event to run some (several) checks in my form. This is a bound form to a table and it has these properties set:
- Cycle: current record;
- Data entry: yes.
In the form there is a button to save current record and move ahead to another (blank) record.
Code for the Form_BeforeUpdate event is the following:

	Code:
	Private Sub Form_BeforeUpdate(Cancel As Integer)
'### check if mandatory fields are blank/null ###'
Dim ctl As Control
Dim testo As String

For Each ctl In Me.Controls
    Select Case ctl.ControlType
        Case acTextBox, acComboBox
            If ctl.Tag = "Required" And IsNull(ctl) Then
              testo = ctl.Controls(0).Caption
              testo = Left(testo, Len(testo) - 1)
              MsgBox "The following field is required: " & vbCrLf & vbCrLf _
              & "- " & testo
              Cancel = True
              ctl.SetFocus
              Exit Sub
            End If
    End Select
Next ctl

'### Check lenght of Latitude field ###'
If Len(txtLat)  7 Then
    MsgBox "Latitude is not correct, please complete all components of the field."
    Cancel = True
    txtLat.SetFocus
    Exit Sub
ElseIf IsNull(txtLat) Then
    Dim textMessage As Integer
        textMessage = MsgBox("Latitude data is not mandatory, but the distance calculation feature in the " _
        & "flight data center will not be available. Do you want to add latitude?", vbYesNo)
            If textMessage = vbYes Then
                txtLat.SetFocus
                Exit Sub
            Else
            End If
Else
txtLat = UCase(txtLat)
End If

'### Check lenght of Longitude field ###'
If Len(txtLon)  8 Then
    MsgBox "Longitude is not correct, please complete all components of the field."
    Cancel = True
    txtLon.SetFocus
    Exit Sub
ElseIf IsNull(txtLon) Then
    Dim textMessage2 As Integer
    textMessage2 = MsgBox("Longitude data is not mandatory, but the distance calculation feature in the " _
        & "flight data center will not be available. Do you want to add longitude?", vbYesNo)
            If textMessage2 = vbYes Then
                txtLon.SetFocus
                Exit Sub
            Else
            MsgBox "All data you inserted will be saved shortly."
            End If
Else
txtLon = UCase(txtLon)
End If

'### checks for the Latitude field components ###'
If Mid(txtLat, 2, 2) >= 90 Then
    MsgBox "Latitude cannot be higher than 90° degrees, please edit the field accordingly"
    Cancel = True
    txtLat.SetFocus
ElseIf Mid(txtLat, 4, 2) >= 60 Then
    MsgBox "Minutes of Latitude field cannot be higher than 60, please edit the field accordingly"
    Cancel = True
    txtLat.SetFocus
ElseIf Mid(txtLat, 6, 2) >= 60 Then
    MsgBox "Seconds of Latitude field cannot be higher than 60, please edit the field accordingly"
    Cancel = True
    txtLat.SetFocus
Else
txtLat = UCase(txtLat)
End If

'### checks for the Longitude field components ###'
If Mid(txtLon, 2, 3) >= 180 Then
    MsgBox "Longitude cannot be higher than 180° degrees, please edit the field accordingly"
    Cancel = True
    txtLon.SetFocus
    Exit Sub
ElseIf Mid(txtLon, 5, 2) >= 60 Then
    MsgBox "Minutes of Longitude field cannot be higher than 60, please edit the field accordingly"
    Cancel = True
    txtLon.SetFocus
ElseIf Mid(txtLon, 7, 2) >= 60 Then
    MsgBox "Seconds of Longitude field cannot be higher than 60, please edit the field accordingly"
    Cancel = True
    txtLon.SetFocus
Else
txtLon = UCase(txtLon)
End If
End Sub

Save button has a cmdSave_click event:

	Code:
	Private Sub cmdSave_Click()
Call Form_BeforeUpdate(False)
DoCmd.RunCommand acCmdSaveRecord
DoCmd.GoToRecord , , acNewRec
End Sub

When I click on the cmdSave button the BeforeUpdate event doesn't work as expected. A MsgBox comes up twice (The following field .... is mandatory), I press OK on the MsgBox and the procedure try to run the DoCmd.RunCommand acCmdSaveRecord given an error: "Property not found". Debugging shows me the row where DoCmd.RunCommand stands.
How to get running the BeforeUpdate correctly and, if all checks are confirmed, saving the records as wanted?
Thanks for your help.
Bye.

Riccardo




Hi All,

I am still using Access 2003. Some of the users of the database I creat are quite old. Have difficulty reading small fonts.

I use "DoCmd.RunCommand acCmdZoomBox" on double click events of text and memo fields for a zoom box to pop up.

My question is how I make the fonts bigger and bolder automatically instead of the standard size 8. The users have to click on the Fonts button and change to their requirements and they are annoyed!

Thanks in advance

Raghu from Melbourne




I have got a form that updates a sql database table 'Problem'.

One of the combo boxes on the form is called product name which is based on the contents of a view from sql (the view is the table 'products' sorted).
Once a choice is made from the combo (on change) the record is saved using docmd.runcommand accmd SaveRecord

I thought the process was working fine until I attempted to add another entry selecting a product name that I had already used, at this point the on change command of SaveRecord causes all the fields to chage to #deleted

I have tried loads of things to try and get round this, I have found that if a product name is select that has not already been used and then the correct product name is chosen the record is saved.

I do think it is the Access side to blame as I can manually add the entry to SQL and if I remove the docmd.SaveRecord and save manually with the little pencil bar it works fine.

Any ideas, reasons why would be very much appreciated...




Hi Folks,

If you use the wizard to create one of the standard buttons on a form, it gives you code for the DoMenuItem method for whatever you are looking for. eg the find button gives:


	Code:
	DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

In another thread it was suggested that this was "old fashioned" and the correspondant suggested:


	Code:
	DoCmd.RunCommand acCmdFind

Can somone give a brief overview of the difference and any advantage of using one over the other?

For a relatively new coder, the wizard is the easiest way to get something up and running and seems to work pretty well.

Regards,

Keith.




I'm wondering about the relative merits of Me.Undo versus DoCmd.RunCommand acCmdUndo. Why would I use one or the other, and when? Is one better than the other?

Generally, I'm using one or the other on forms in BeforeUpdate as part of error-trapping and saving records.

I'm afraid the depth of my knowledge is that I notice that Me.Undo is shorter.

Any help with deepening my understanding? Or pointers to references equally appreciated. Many thanks!




Hi Access Experts!

I try not to post questions on here, most of the time i can find out the answers for myself, unfortunetly i'm completely stuck with this problem.

I'm getting the following error 'The command or action 'SaveRecord' isn't available now.

I've got quite a large fairly complex database, and i use the code below quite a lot for saveing the current record.


	Code:
	If Me.Dirty Then
    DoCmd.RunCommand acCmdSaveRecord
End If

Most of the time it works no problem, but it doesn't work so well in the following piece of code.


	Code:
	Private Sub imgEmailUp_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.imgEmailDown.Visible = True
    Me.imgEmailUp.Visible = False
    If Nz(Me.SupRatifiedBy.Value, "") = "" And Me.SupRatified.Value = False Then
        Select Case MsgBox("Do you want to forward this investigation on for ratification?" _
                           & vbCrLf & "" _
                           & vbCrLf & "*Note: you cannot complete the investigation" _
                           & vbCrLf & " unless it has been ratified." _
                           & vbCrLf & "" _
                           , vbYesNo Or vbQuestion Or vbDefaultButton1, "Investigation Needs Ratification")
                
            Case vbYes
                bolRatifiedchk = True
                GetCheckValues 'start the investigation module
                Me.SupResolvedBy.Value = glbUserName
                Me.SupDateResolved.Value = Date
                If Me.Dirty Then
                    DoCmd.RunCommand acCmdSaveRecord
                End If
            Case vbNo
                Exit Sub
        End Select
            Exit Sub
    End If
        Select Case MsgBox("You are about to inform goods-in that you have completed" _
                           & vbCrLf & "you part of the supplier investigation." _
                           & vbCrLf & "Do you want to continue?" _
                           , vbYesNo Or vbQuestion Or vbDefaultButton1, "Advise Goods-In To Complete?")
            
            Case vbYes
                Call SupplierInvestComplete 'send goods-in an email
                If Nz(Me.SupDateResolved.Value, "") = "" Then 'check to see if the field is empty
                    Me.SupDateResolved.Value = Date
                End If
                If Nz(Me.SupResolvedBy.Value, "") = "" Then 'check to see if the field is empty
                    Me.SupResolvedBy.Value = glbUserName
                End If
                Me.SupRatifiedBy.Value = glbUserName
                Me.SupRatifiedDate.Value = Date
                If Me.Dirty Then
                    DoCmd.RunCommand acCmdSaveRecord
                End If
                '-------------Update Supplier Record-------------
                DoCmd.SetWarnings False
                DoCmd.OpenQuery "qryudSupplierInvestigation"
                DoCmd.SetWarnings True
                '----------------------End-----------------------
            Case vbNo
                Exit Sub
        End Select
End Sub

The thing i'm really struggling with is, where i use the DoCmd.RunCommand acCmdSaveRecord thats in green, it works fine, and the record is saved. Where i use the same code thats in red, thats when i get the error.

I can't understand why it should work eairlier in the code, and not later?
can anyone give me some insight to the 'DoCmd.RunCommand acCmdSaveRecord' command?

Thanks

Darren.




Hi Guys

Does anyone know if it is possiable to caputre and store what a user inputs into a search box.

I have a button that focuses on a field and then opens the search dialog, but I could do with being able to capture the information they are looking for.


	Code:
	    Me.fieldname.SetFocus
    SendKeys "%ha%n", False
    DoCmd.RunCommand acCmdFind

Thanks

Hawk




I am using the following command to delete records.
DoCmd.RunCommand acCmdDeleteRecord which is fine if the user presses OK but if the user presses No it just crashes. How do I code this with my own error messages. Below is what I have so far but that deletes whether you press or no as the delete is already done.

Dim Msg, Style, Title, Response
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
Msg = "You are about to delete a line. Do you really want to do this?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Warning" ' Define title.
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
Else ' User chose No.
DoCmd.Hourglass False
Exit Sub
End If




Ok, I finally have it working the way I like. It's really slick - the main form (set to "PopUP" and with docmd.runcommand accmdappminimize line in the On_Open event) opens with customized icon (in titlebar and in windows taskbar) and behaves like a standalone program (you only see Access the first few seconds during opening before it's minimized).

The form can be minimized to windows taskbar and clicked to restore it (form's maximize button is disabled, for appearance sake). it can also be accessed via the alt-tab windows menu, where it also appears with a custom icon. so it's really slick, it behaves just like a standalone app. read on for the ", but..."

I also wrote 2 functions to handle reports.

1st (fnOpen, I also use it for forms, etc. via arguments, but only the reports have the following logic). This one closes my main form, maximizes Access (which has all menus/toolbars disabled, so it doesn't really look like Access, looks like a report viewer). This function is placed into all report buttons' On_Click event with report name as argument and object type (3 for report, because 0=table, 1=query, 2=form, 3=report in my fnOpen).

2nd. (fnCloseReport) is placed into all reports' On_Close event. This function opens my main form again on the tab from which report was called. It works, but herein lies the problem: after the form reopens, it no longer has the whole application's custom icon, but the Access "form" icon. And after this, if minimized to windows taskbar it actually minimizes as resized mini-window above the Start button (as has been described by others, just as it would within Access it it were visible) and Access appears minimized in the windows taskbar, so somehow the whole cool "standaloneness" is turned off.

I wonder if anyone has some suggestions for this. I spent some time researching and testing this and really like the functionality. When the form is displayed without Access, it cannot be right-clicked (at all), which is very useful (although I know there are other ways of protection).

BTW, all my other windows (all popup/modal) appear on top of the main form with no problems. I have "File Open" and "Save As" windows common dialogs that my app calls (via API) and I also have a custom form acting as dialog box (I use the acDialog intrinsic constant when I open it from code). so mutliple windows are not an issue as some have suggested.

Thanks in advance!




I have a form with a clear data button that clears the data that is entered on a search form and also refreshes the datasheet view of the subform.

The code for the command button is below:

Private Sub Command25_Click()
State = ""
City = ""
Zip = ""
ListPrice = ""
Bedrooms = ""
Baths = ""
sqft = ""
DoCmd.RunCommand acCmdRefreshPage
End Sub

When I click the Clear Data button it clears the fields above.

Everything works fine but when I enter this criteria in my "Price List" list field in my design view query

>=([Forms]![Searchf]![Listprice])

the clear button does not clear my data in my subform datasheet view. It enters

"Name?

in every field.


But if I change the criteria to:

Like "*" & [Forms]![Searchf]![ListPrice] & "*"

The Clear Data command button works fine but I need this criteria to work for me

>=([Forms]![Searchf]![Listprice])

Why does the Like criteria work for the Clear Data button and not the >= criteria?
What can I change.
Thanks




Hi there

I have to make the access project to use the sql server 2000 backend. I have a problem while executing the project the command

DoCmd.RunCommand acCmdSaveRecord

It gives me following error
Run-time error '2046'
The command or action 'SaveRecord' isn't available now.

Can any body plz help me this regards




I don't understand what this line of code does but I'm guessing it automatically saves the current record from my form to the underlying table. When it saves it I do not know.

If that's correct then I'm messing it up somehow by adding 3 extra lines. See below.

The following code works just fine as is but it doesn't work if I take out the three "rem-out" rows of code - why?

It seems to me that it should run the append query in the middle - no problem. The append query works off the table where the data just got acCMDSaved but I'm no programmer. Help.

Private Sub cmdExit_Click()
If Len(Me.PN) > 0 And Len(Me.REV) > 0 And Len(Me.Part_Description) > 0 Then
DoCmd.RunCommand acCmdSaveRecord
'DoCmd.SetWarnings False
'DoCmd.OpenQuery "Q_AppendPNDescER"
'DoCmd.SetWarnings True
Form_F_PartAdds.cboPNAddRev = Me.REV
DoCmd.Close acForm, "F_PartNew"
Else
MsgBox "You must provide a value for PN, Rev, Description"
End If

End Sub




I am trying to make the user interface more user-friendly by creating a two
command buttons that will open the dialog box to insert an object into an OLE
field.

Private Sub CmdInserir_Click()
On Error GoTo Err_CmdInserir_Click
DocDigital.SetFocus
DoCmd.RunCommand acCmdInsertObject
Exit_CmdInserir_Click:
Exit Sub
Err_CmdInserir_Click:
DocDigital.SetFocus
'MsgBox "Deverá mencionar o caminho", vbInformation
Resume Exit_CmdInserir_Click
End Sub

Private Sub CmdOrigem_Click()
DocOrigem.SetFocus
DoCmd.RunCommand acCmdInsertObject
Exit_CmdOrigem_Click:
Exit Sub
Err_CmdOrigem_Click:
DocOrigem.SetFocus
'MsgBox "Deverá mencionar o caminho", vbInformation
Resume Exit_CmdOrigem_Click
End Sub


This worked once. Nothing changed but the code won't run anymore. Now, I
get error 2001, "You have cancelled the previous operation"

What did I do wrong? How do I fix it?

Thanks,
Victor Hugo




I have a simple form in access.

There is one field on the form , DocID, which has the name of a document. When the form is loaded, I want the docID to be copied onto the clipboard so the user can paste this into another program without having to do a manual keyboard or mouse routine. After doing the copy, it moves the focus to the next field where a user could paste his results.

So, for the oncurrent event I wrote:

'copy the doc id value to the clipboard

DocID.SetFocus
DoCmd.RunCommand acCmdCopy

'Move focus to DocID1 field
DocID1.SetFocus


This works great if you acutally work with the record. No problems. The problem arises when/if the user scrolls through the records, instead of updating the record. Then I get the error:

Run-time Error '2046':
The command or action 'copy' isn't available now.

When I hit debug, it goes to the line: DoCmd.RunCommand acCmdCopy

Can anyone help me figure out why this doesn't work when you are browsing/scrolling through the recordset?




I'm trying to add a control button on the main form of my database so that the users can do a lookup of customers by their last names.

I would like it to have the same functionality as the Find & Replace button on the toolbar. Specifically, I want to make sure that the lookup is done only on the LastName field in the database.

Of course, nothing is as easy as it should be. My coding brings up the F&R window, but the "Look In" field is grayed out and defaulted to the entire form, not the "Last Name" field.

There has to be some way to set this... but so far, no such luck finding it.

My code is the default:
--------------------------------------
Private Sub FindCustomer_Click()
Screen.PreviousControl.SetFocus
DoCmd.RunCommand acCmdFind

Exit_FindCustomer_Click:
Exit Sub

End Sub
--------------------------------------

I've also tried it with a suggested SendKeys setting:

--------------------------------------
Private Sub FindCustomer_Click()
Screen.PreviousControl.SetFocus
SendKeys "%ha%n%e", False
DoCmd.RunCommand acCmdFind

Exit_FindCustomer_Click:
Exit Sub

End Sub
--------------------------------------

So what am I missing here? (Days like this, I miss dBase!)

Thanks!

Ron Notarius, IT Support
All-Clad Metalcrafters LLC
Canonsburg, PA
rnotarius@allclad.com




I have been developing a database in Access 2003 for some time now it has been running in 2003 and Access 2007 successfully. When I added a Find and Replace button it works in 2003 but in Access 2007 it highlights it then crashes, no error messages.
The details are:
*The button is on the main form and searches a SubForm displaying as a DataSheet.
*Tried both DoCmd.RunCommand acCmdFind and DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70 always same effect.
*Tried various set focus options - no change.
Me![tblComponent Subform3].SetFocus
[tblComponent Subform3]!SerialNumber.SetFocus
Screen.PreviousControl.SetFocus
*There is an OnCurrent Event on the SubForm yet it is OK in 2003.

Any help would be well received, thanks