I am trying to locate a query, and cannot find it.
Where can I find qMyQuery?
Dim stDocName As String
stDocName = "qMyQuery"
DoCmd.OpenQuery stDocName, acNormal, acEdit
By pressing F11 in Access 2010 you can open the navigation pane (if not already open). From here, select “Queries” or “All Objects” using the small down arrow at the top of the navigation pane to view the queries in the mdb.
type this docmd.SelectObject acQuery ,"qMyQuery",true an press Enter
in "Immediate" window and Access will select your Query in database window.
To open "Immediate" window you can press Ctrl+G
Related
I'm not very expert in using this Microsoft access, I just try my best and try to follow the tutorial on youtube. I'm stuck with showing all records in the preview report. for now when I select the place that I want, the preview report just showing the selected places. But when I click the show all button and I click the preview report, it still comes out with selected places, not all records. Any changes that I need to change at the 'show all' button?
Private Sub cmdshowall_Click()
Dim showall As String
showall = "SELECT * FROM Register"
Me.RecordSource = showall
Me.Requery
Eng Sub
I've inherited an MS Access project and I'm trying to make changes to some of the forms. However, when I open the file in MS Access 2016, I'm not able to see the navigation menu, top ribbon, or the edit design in order to make any changes. I've searched that there are several ways to bypass this but also found out that each one of them can be disallowed by the developer. If each one can be disallowed, how would another developer make changes?
Below is what I've tried:
Pressed F11 but nothing shows up
Keep SHIFT clicked while double clicking the file but nothing shows up
Pressed CTRL+G to open VBE but nothing shows up
Are there any other ways for me to view edit, navigation, ribbon menus on this access database so that I can make changes to it?
Yes, you can easily bypass such "security" measures using OLE automation.
Use the following code from another Access database (or VBA application)
Public Sub UnlockAccess()
Dim pathToFile As String
pathToFile = "C:\Path\To\My\File.accdb"
Dim db As DAO.Database
Set db = DBEngine.OpenDatabase(pathToFile)
'Set some restrictive properties back to normal
On Error Resume Next
db.Properties!StartUpShowStatusBar = True
db.Properties!AllowFullMenus = True
db.Properties!AllowShortcutMenus = True
db.Properties!AllowBuiltInToolbars = True
db.Properties!AllowSpecialKeys = True
db.Properties!AllowToolbarChanges = True
db.Properties!AllowByPassKey = True
db.Close
On Error GoTo 0
Stop 'You can open up the database using the shift bypass key here, and enable whatever you want'
Dim app As New Access.Application
app.OpenCurrentDatabase pathToFile
app.Visible = True
app.UserControl = True
app.DoCmd.SelectObject acTable, , True
End Sub
An alternate way to modify security is to modify the restrictive VBA code. If you can't open the editor directly from the file, you can open another file, set a reference to the file you want to modify, and modify it from there.
I am new on access and what I am trying to do is a select with a criteria so I created a query with the wizard and seted the criteria with a text from a form ([Forms]![Form1]![Transacao]) and created a button to run the query at the first time works great but when I type something else and click the button the datas do not refresh. What I have to do to refresh? I've tryed to add refresh on the event click of the button and did not work.
Thanks in advance for your help.
In Access, a query is usually opened in a default Datasheet view. This default datasheet is contained in a window (or tab) that is only accessible using Macros or DoCmd in VBA.
Once a query window is open, its data will not necessarily update automatically when new records are added to the underlying table(s). The datasheet needs to be "requeried". (Incidentally, the term "refresh" is usually reserved to mean "redrawing" a window on the screen and has nothing to do with the data. This is especially the case in programming and development environments which deal with data and drawing/painting windows and controls on the screen.)
Here is one way to force a query to update its data (when open in its default datasheet view):
DoCmd.OpenQuery "QueryName"
DoCmd.Requery
Calling OpenQuery should also activate the query window if it is already open. If you find that the windows does not activate, you can also call DoCmd.SelectObject acQuery, "QueryName" before DoCmd.Requery.
The DoCmd methods correspond to Macro actions, so if the query is activated by a Macro, just add the Requery action to the macro after the OpenQuery or SelectObject actions. Leave the Control Name parameter of the Requery action blank to force the entire query to updated.
I know this question is a bit stale at this point, but since I couldn't find a suitable answer to this question and the above answer didn't work for me (and still hasn't been accepted), I thought I'd offer my solution for those few poor saps still stuck developing applications in Access. My use case was slightly different (changing the underlying SQL of a query, then opening/refreshing it), but the same principle could be applied. The gist is to first check to see if the query is open and close it if it is. Then open it up again.
To do this, paste this code into a VBA module:
Public Function open_or_refresh_query(query_name As String, Optional sql_str As String = "")
' Refresh or open an existing query
' query_name: Name of the query
' sql_str: optional new SQL string if changing the underlying SQL. If not given,
' the query will open with its existing SQL string
On Error GoTo err_handler
Dim qdf As QueryDef
' Loop through each query in the DB and find the one of interest by name
For Each qdf In CurrentDb.QueryDefs
If qdf.Name = query_name Then
' If the query is open, close it
If SysCmd(acSysCmdGetObjectState, acQuery, query_name) <> 0 Then
DoCmd.Close acQuery, query_name, acSaveNo
End If
Exit For
End If
Next qdf
Set qdf = CurrentDb.QueryDefs(query_name)
' Reset the SQL if new SQL string was given
If Len(sql_str) > 0 Then qdf.sql = sql_str
' Close the QueryDef object to release resources
qdf.Close
' Open the query in default datasheet view
DoCmd.OpenQuery query_name
exit_function:
Exit Function
err_handler:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Error"
Resume exit_function
End Function
At this point you could call this function from any other VBA code in your project. To open/refresh a query from a macro as the OP wanted to do, create a new macro and add a RunCode action with open_or_refresh_query("my_query") in the Function Name field, changing my_query to the name of your query.
I have Microsoft Access Form where I have table of data I want to be able to add a filtering toolbar to the form in MBE mode. Note MBE not in the designer mode of MDB. I.e. I want a filter on the distributed MBE file.
In Form.Open event I added:
Private Sub Form_Open(Cancel As Integer)
DoCmd.ShowToolbar "Ribbon", acToolbarYes
DoCmd.ShowToolbar "ribbonMain", acToolbarYes
DoCmd.ShowToolbar "Menu Bar", acToolbarYes
End Sub
I also tried
Private Sub Ctl__Click()
Dim db As DAO.Database
Dim prop As DAO.Property
Set db = CurrentDb()
DoCmd.ShowToolbar "Ribbon", acToolbarYes
End Sub
Also, Access Button - > Access Opiton ->Current Database
Under the Ribbon and Toolbar Options:
Checked Allowed Built-in Toolbars. Also, Ribbon Name is "ribbonMain".
I still cannot see the Toolbar in the top of Form. What am I missing in the code or access page set up. I am running on MS Access 2003. I would really like to have same filtering you see in design mode of a table in an deployed MBE file.
I would suggest putting the code in the On load even instead also DoCmd.ShowToolbar "Ribbon", acToolbarYes may cause error in access 2003. When i was building my database i found this post helpful.
http://www.access-programmers.co.uk/forums/showthread.php?t=97578
Access 2003 FORMS: when I set at runtime with VBA the "RowSource" for a ListBox persist even if I close and then open...
How to fix this, I would like to have clean "RowSource" when I open a new form...
You can set the RowSource during form load.
Private Sub Form_Load()
Dim strSql As String
strSql = "SELECT f.id, f.fname FROM foo AS f ORDER BY f.fname;"
Me.lstNames.RowSource = strSql
End Sub
Setting the RowSource of the List Box changes the Form's design. Access wants to save those changes for you (actually, I think the default behavior is to ask). If you want to close the form without changes, put this code in a Command Button's OnClick:
DoCmd.Close acForm, Me.Name, acSaveNo
The last parameter tells Access to not save the changes. Another alternative is what HansUp gave you in his second comment to his answer--just disable the List Box. Then when you figure out what its RowSource should be (on user input), set the RowSource & the Enabled property.