Automatically fill out textbox doble clicking on an item in a listbox - textbox

Another beginners question, but this time about MS Access Controls.
I have a form where I have a list box full with many items.
What I need to do is when I double click on one of this item stored in the list box should all the textbox filled with an item stored on a different field from the same row where from my table.
I checked many tutorials already but didn't found a good solution.
Thanks for any help!
EDIT:
I have a table with several fields. The list box have the items from the first field(ID). The rest of the fields(Tile, Delivery Date, etc...) represented by text boxes in my form.
When I double Click on one item from the list box will populate the text boxes.
If I select the 5th item from my list box which represents the 5th row from my table every text box should have their item from the same row from the fields represented in the table.
I only want to edit the data stored in the table with this form.

Ok I finally get a solution for this one.
I using the DLOOKUP to get the data pulled to my form after the double-click event.
Dim ctrloop
For Each ctrloop In Me.lbReportID.ItemsSelected
strReportID = Me.lbReportID.ItemData(ctrloop)
Next ctrloop
Me.txtTitle = DLookup("[Title]", "tblreports", "[ID No] = '" & strReportID & "'")
The loop stores all report ID I have in my table. The DLOOKUP using this as a filter. It's like the WHERE in SQL.
When the program run will fill out my Title textbox looking through the title field in my tblreports table filtered with the strReportID.
It's working similarly like this SQL query which I using in a different textbox:
SELECT tblReports.[ID No]
FROM tblReports
WHERE (((tblReports.WorkPacage) = 'CDS'))
AND (((tblReports.State) <> 'Complete'));

Related

Google Sheets sort checked checkboxes relevant data by order

In my sheet I have checkboxes and item names next to them. Once I check a checkbox, the item name is displayed in the main sheet in column C and the belonging icon in column B. Column E and F are for the buyer name and the price.
Issue is, since the items are automatically sorted A-Z, the buyer name and price for alot of items messes up once new items are added.
For example an item that starts with a "G" moves automatically one row down once another item is added that starts with any letter before "G".
Is it possible to sort the list by order of addition of the checked checkboxes?
https://docs.google.com/spreadsheets/d/1yKYFnWgJN823bd6PjDy-Ozi20gF2UckEUK9I3CXgerI/edit?usp=sharing

Selecting an item from a listbox to show more items in another listbox?

Alright, so i have a problem with my programming, i have three checkedlistboxes, one called "lstShows" 2nd is called "lstSeasons" and third is called "lstEpisodes" and i have two comboboxes that have seasons and episodes in them, one combobox is called "cbSeasons" and 2nd is called "cbEpisodes. so what i'm trying to do is, when i press on an item in lstshows, i want to be able to assign to it items from lstSeasons, and when i want to click on an item in seasons i want to be able to assign items to it in lstepisodes
So for example lets say, a tv shows contains 10 seasons, so i add that tv shows and assign 10 seasons for it, then season 1, has 20 episodes, and seasons 2 has 15 episodes, i want to be able to add items to each different show, and season. i have been looking every where but i could not find anything.
Here is the layout https://www.dropbox.com/s/u6xc3sb43ksq8qr/Capture.PNG?dl=0
and i tried to do the code, i done this but it does not work.
Dim item As String = lstSeasons.SelectedItem
lstEpisodes.Items.Add(item)
I really need help with this.
Thank you.
First of all, your data must be stored somewhere.
For example, you can have one worksheet per show, have the seasons in column A and for each season have the episodes in the same row (starting at column B). If you don't want this data to be seen, just hide the sheets.
So if I understood correctly, first you want to select a show, then the seasons of this show appear in the 2nd listbox, and then when you select a season the episodes of this season appear in the 3rd listbox.
First, you need to add all you shows to the 1st listbox. Here, I'll assume that you have 10 shows, that their corresponding worksheets are Worksheets(1) to Worksheets(10), and that the name of the worksheet is the name of the show (but you can do as you wish, for example storing the show's name in a particular cell).
Dim showName as String
For i = 1 To 10
showName = Worksheets(i).Name
lstShows.AddItem showName
Next i
Then, to get the seasons listbox to change when you select a particular show, you can do this :
Private Sub lstShows_Change()
Call Me.lstSeasons.Clear
showName = Me.lstShows.Value
Dim sh as Worksheet
Set sh = ThisWorkbook.Sheets(showName)
rowCount = sh.Cells(sh.Rows.Count,"A").End(xlUp).Row
Dim i As Integer
For i = 1 To rowCount
Me.lstSeasons.AddItem sh.Cells(i,1).Value
Next i
End Sub
And to get the episodes listbox to change when you select a particular season, you can do this :
Private Sub lstSeasons_Change()
Call Me.lstEpisodes.Clear
showName = Me.lstShows.Value
Dim sh as Worksheet
Set sh = ThisWorkbook.Sheets(showName)
rowCount = sh.Cells(sh.Rows.Count,"A").End(xlUp).Row
Dim colCount As Integer
Dim i As Integer
Dim j As Integer
For i = 1 To rowCount
If Me.lstSeasons.Value = sh.Cells(i,1).Value Then
colCount = sh.Cells(i, sh.Columns.Count).End(xlToLeft).Column
For j = 2 To colCount
Me.lstEpisodes.AddItem sh.Cells(i,j).Value
Next j
Next i
End Sub
Hope this will help !
First thing I believe you need to do is to put a multi dimensional array to store your information.
More details about jagged arrays: https://msdn.microsoft.com/en-us/library/hkhhsz9t(v=vs.90).aspx
so you can use it this way for example:
Dim shows(50)(50) As string
This will give you 50 "shows" with 50 episodes each. now you can change those using the program as needed.
Now into the next part which is inserting those in. You can modify them by assigning a value by
shows(1)(12) = "ep12nameofshow1"
Where you can assign the string as a variable if you want to be able to manually change the name during runtime
Now you want to add the items to your listbox! So lets go over that with a great little for-loop
For Each episode As String In shows(1) 'show number here
lstEpisodes.Items.Add(episode)
Next
please note that I didn't test this since I don't have access to most of your code so please inform me if there are any problems you are facing.
Update This code should be working:
1- Add this at top of your page (below class declaration)
Dim showEpisodes(99)(99)() As String
think of it as showEpisodes(Show#,Season#,Ep#)
2- Add values to your array. How you do that is up to you (use a file, database or just predetermined values. You can even put them in run time. But that's another thing for another question!)
3- Add this part to your season's code
For Each element As String In showEpisodes(lstShows.SelectedIndex)(lstSeasons.SelectedIndex)
lstEpisodes.Items.Add(element)
Next

do some calculations in a table using dropdowncombo

I have a field in my database called 'Stock'. It displays how many items are there remaining for sale.Now I have a dropdowncombo with values like 1,2,3 etc... So now when I select an item in the grid and click the button SELL I would like the 'Stock' field of the item in question (in the grid) to decrease by the amount that was in the combo. So if the 'stock' was 100 and I sell 5 (dropdowncombo value) I would like the grid value to display now 95. I hope you know what I mean... I could do this with inserting a calculated field but I do not want to. Better an UPDATE ... Any ideas
something like UPDATE MyTable set STOCK = (Mytable.fieldbyname('stock').asInteger - dropdowncombo1.value)
dont have delphi here with me so unsure does this work on selected record in the grid...
abstable1.edit;
abstable.FieldByName('stock').value := abstable.FieldByName('stock').value - strtoint(cxcombobox1.text);
abstable1.Refresh;
This does the job ...

access 2007: entering multiple entries in a single bound text box

I have a single form, linked to a single table. The form has three bound text boxes, each allow for data entry to the table. In the text boxes you enter a date, a dollar amount, and a client to bill for the postage. My problem is what if I have multiple clients, billed to a single expense.
I want to alter the client entry text box so that i can type in multiple clients, seperated by a comma, and access will know to take the amount entered and divide it between the number of clients entered.
Is this possible? Any help would be appreciated! I taught myself access for the most part and am not very savvy.
Let me start by saying this is not a good idea, however, if it is for your personal use, you can use VBA to split the text string and get a count, you are likely to run into a number of problems, depending on how the bound field is set up.
What I would suggest is a listbox, your two text boxes, and a subform. Using a muti-select listbox you can choose one or several clients. A little code will allow you to iterate through the list and insert a record into a table for each client, with the date and the amount divided by list count. The subform will show the inserted records for checking.
For example:
For Each itm In Me.ListBox.ItemsSelected
sSQL = "INSERT INTO MyTable (ClientID, Amount, InvDate ) " _
& "VALUES ( " & Me.ListBox.Column(0, itm) & "," _
& Me.txtAmount / Me.ListBox.ItemsSelected.Count & ",#" _
& Me.txtDate & "#)"
CurrentDB.Execute sSQL, dbFailOnError
Next
Me.SubformControlName.Form.Requery

Delphi QuantumGrid GetSelectedRowIndex after sorting

I have D2006 and I am using DevExpress QuantumGrid 6 in a project. I am using it in unbound mode. I have several rows and I need to trigger an action when user select a row and click a button. That works fine when the grid is not sorted by user. I use this code to know the row the user has selected:
index := cxMainTable.DataController.GetSelectedRowIndex(0);
cxMainTable.DataController.Values[index, 0];
But when the user sort the grid by clicking in a column header, the index returned is right for the current order displayed but the values the second line returns is the value that you would expect if the grid was not sorted.
Thanks.
You have to distinguish between records and rows.
Maybe TableView.DataController.FocusedRecordIndex is what you want?

Resources