I am not able to scroll the scroll bar in the browse to view more results. How can I achieve this?
DEFINE QUERY BROWSE-4 FOR Customer.
DEFINE BROWSE BROWSE-4 QUERY BROWSE-4 NO-LOCK DISPLAY custNum name /* ENABLE name */ WITH NO-ROW-MARKERS SEPARATORS SIZE 32 BY 6.46 FIT-LAST-COLUMN. .
open query browse-4 for each customer no-lock.
enable browse-4.
wait-for window-close of current-window.
Just replace "FOR" with "PRESELECT" in the query:
DEFINE QUERY BROWSE-4 FOR Customer SCROLLING.
DEFINE BROWSE BROWSE-4 QUERY BROWSE-4 NO-LOCK DISPLAY custNum name /* ENABLE name */ WITH NO-ROW-MARKERS SEPARATORS SIZE 32 BY 6.46 FIT-LAST-COLUMN. .
open query browse-4 PRESELECT each customer no-lock.
enable browse-4.
wait-for window-close of current-window.
Just note that performance wise it can be a bad idea, as you are reading all the table contents at once...
Related
Assume a table that has many pages and I only want some of it, for example
SELECT * FROM t WHERE...
From pg_class.relpages I know how many pages are there, how can I access some page like
SELECT * FROM t WHERE PAGE_NUMBER=1
Since you mention relpages I assume you are talking about "physical" pages where the data is stored on disk. In general you should mind your own business and let the database server mind its own business. But if you don't want to do that, the you can reference tuples by the hidden system column "ctid", which is a composite consisting of the page number and the slot within the page.
select * from pgbench_accounts where ctid between '(18,0)' and '(18,65535)';
This is the 19th page, as page numbers start at 0. Slot numbers start at 1, but for convenience you are allowed to reference slot 0 as if it were a valid (but empty) slot.
Note that until very recent versions, this will not be fast as it would scan the whole table and filter out the disqualified rows one by one.
For that, you need a sort order. For example
SELECT * FROM t WHERE ...
ORDER BY customer, created_ts;
Make sure that the sort condition is unique. If it isn't, add the primary key at the end.
Then you create an index for the ORDER BY condition:
CREATE INDEX ON t (customer, created_ts);
Then you select the first page of 50 items like this:
SELECT * FROM t WHERE ...
ORDER BY customer, created_ts
LIMIT 50;
You display the page and remember customer and created_ts from the last result row in <latest_cust> and <latest_ts>.
The next page is fetched with
SELECT * FROM t WHERE ...
AND (customer, created_ts) > (<latest_cust>, <latest_ts>)
ORDER BY customer, created_ts
LIMIT 50;
and so on.
This method (it is called “keyset pagination”) is efficient and quite stable in the face of concurrent data modifications.
The management staff in my department has been asked to record any and all errors committed by our team. I created a database to store them and a simple form for the management team to use to record each error. Several fields are referencing other tables such as Staff, issue category, root cause, etc...
We need to be able to search the forms for specific records to either update or review, and I have found the best way for us to search is by filtering the forms based on the individual who committed the error. Here is the code that I am using for the search button:
Private Sub SearchRecord_Click()
Dim Search As String
Search = InputBox("Please enter who committed the error", "Name", ErrorMadeBy)
If Search = "" Then Exit Sub
Me.Filter = "ErrorMadeBy = """" & Search & """
Me.FilterOn = True
End Sub
The filter works great, but instead of filling out the name, you have to use the ID number in the Staff table when filling out the Input Box. I'd like to be able to input the name (or part of the name) instead of having to have everyone memorize the ID numbers from the staff table.
What I do in these cases?
Fire up the query builder - left join in those extra tables (with the text parts in place of the id).
So be it a part number, quote number for a project etc? Just left join in those tables in the query builder and save that query.
Now, your search box and code can be somthing like:
dim rst as DAO.RecordSet
strSQL = "Select * from MyCoolQuery where PartName like '" & txtPartName & "*'"
set rst = currentdb.OpenRecordSet(strSQL)
if rst.EOF = false then
me.RecordSet.FindFirst "PartID = " & rst!PartID
end if
In fact, you can even often left join in those extra tables right into the current form, and even use ctrl-f to search if the said text boxes are place on the given form. However, I tend to separate out the search process from the actual form. So I might build a search form, say like this:
So in above, they can search say by a Hotel name, or project name or whatever. Becuase the one query has the text parts, then they can be searched. But I put the query results into a grid and each row of course has the PK ID, and thus a search could result in 10 matches, they are now free to click on any row - and i jump to the form to display the one records.
eg: the row click button does this:
docmd.OpenForm "frmTourBooking",,,"ID = " & me!ID
So, this makes for a great work flow. Users search, see, pick and then jump to the form with the one record, and then close and return back to search form - and often it has the several "hits" from that search that you want to work on anyway.
I'd like to customize the name of each Query Result tab to something other than that default name.
I use to execute multiple queires, but each time the the output displayed as QUERY RESULT 1, QUERY RESULT 2 .... so on. Its difficult to identify and verify the matching SQL Query.
so i want to set the QUERY RESULT tab name, so that it displays(Output) the customized name instead of Default Name. E.g (setting to Table_name, search names, key words to identify the parent query triggered) etc.,
You cant rename these tabs via code/SQL, but you can use your mouse.
But you really shouldn't need to.
"Its difficult to identify and verify the matching SQL Query"
If you mouse over the tab, it shows you the SQL/code behind it. You can also click the SQL button to copy the code to the clipboard.
I have a form with a subform. The record source for the subform is as follows:
SELECT [firstID], [secondID], [AAA], [BBB], [CCC], [DDD]
FROM Table1
WHERE firstID = [Forms].[frm1].[txtfirstID];
The subform groups the records together on the basis of txtfirstID but when I advance through the record selector it goes through every record, as expected. I would like to know if there is a way to click through the groups rather than each record within each group. I'm open to any way of doing it. Perhaps filtering through VBA??
Thanks!
First, add a combo box to your form. Set the RecordSource for the combo box to a distinct list of groups, or, if you have a group lookup table, select * from tblGroups. Set the display field to be group name, and the value field to be group id.
Second, after an item is selected from the combo box, modify the RecordSource sql of the form (your query) so that it uses the current value of the combo box. The value of the combobox would be what your where clause should be looking for.
I think you can do two ways to solve this:
1.- If you related main form to subform by a field. In this case TxtFirstID of Main to FirstID of subform. It do all work when change main form and filter automatically on subform
2.- You can do and event OnChange form TxtFirstID on main form.
Sub TxtFirstID_Change()
Me.subfrmName.Form.RecordSource = "Select * from table1 where firstID=" & Me.TxtFirstID 'change the record source for the SubForm
me.subfrmName.Form.Requery 'Force Access to refresh the Record Source
end sub
I have an Access form with a combobox and a subform on it. The subform is in datasheet mode (the way I want it). What I'm trying to do is make a sort of search function. When something is selected from the combobox, I want the subform's datasheet to scroll to and highlight the matching record.
I do not want to filter the subform (i.e. remove all non-matching records).
Can anyone give me some guidance on how to achieve this?
Something like this:
Private Sub Combo0_AfterUpdate():
With Me.Child0.Form.Recordset
.FindFirst "ID_Field=" & Me.Combo0
End With
End Sub