Populating A Combobox From An Array
Nov 23, 2007Hi,
could anyone help me please, I want to populate a combobox on a form with the values retrieved froma dynamic array.
Thanks in advance.
Hi,
could anyone help me please, I want to populate a combobox on a form with the values retrieved froma dynamic array.
Thanks in advance.
I am trying to improve the performance (loading time) of my main form. The big tip seems to be use SQL in VBA to populate subforms and comboboxes when needed, rather than when the main form loads.
I have a combobox configured for 2 columns, bound column = 1 and column widths set at 2cm each. After a struggle, I have managed to get the combo box to populate with SQL, but only for the first column. My second column appears when I click the down arrow but there is no data showing.
How do I tell the SQL to place the 'Identifier' data in the second column of my combobox? :confused:
Here is the subroutine populates the combobox when the subform loads:
Private Sub Form_Load()
On Error GoTo ErrHandler
'================================================= ========================
'Populate cboEmployeeID with SQL when form loads
'This is done to reduce time taken to load parent form
'================================================= ========================
'Define the SQL text
Dim stSql As String
stSql = "Employee_ID, Identifier, Section_ID, Office_Phone_Ranking, Role FROM [tbl_Prj_Details]"
stSql = stSql & "WHERE (((tbl_Emp_Details.Section_ID)=2) AND ((tbl_Emp_Details.Role)='Technical'))"
stSql = stSql & " ORDER BY tbl_Emp_Details.Office_Phone_Ranking;"
'Populate combo box with SQL
With Me![cboEmployeeID]
.RowSource = stSql
.Requery
End With
ExitHere:
Exit Sub
ErrHandler:
MsgBox Err.Number & " - " & Err.Description & Chr(13) _
& Chr(13) & "Error in 'fsubPrjDet01EDT1': Err 003"
Resume ExitHere
End Sub
Any help/pointers gratefully received :) .
I have three comboboxes on a form – Fabric, Degree, Color.
The row source type for each is Table/Query. The row source is a Select Distinct query. I’m using a query so the list will populate itself. The choices the user makes in the comboboxes are used to filter called forms.
Would there be a way to include the word “ALL” in a drop down list in addition to the data generated by my query. If the user chooses “ALL”, the called page will not be filtered on that particular choice. I just created a record with “ALL” in those particular fields. That seems to work, but I think there might be another way.
Thanks
I have a client table with a field called location. On a reports form that I have, I want to make a combobox for all of the locations, so it could show all the clients from a particular location and also it would reduce the errors due to someone spelling a place name wrong. I could set the source to the location field in the table, but that would show them all in the order they come out and there would be duplicates.
Any help would be cool. Cheers
Bob
I'm populating an unbound ComboBox with a Query via the QueryDesigner. The value of the Rowsource depends on the value of another ComboBox at the main Form.
After several hours of trial and error, I came to the solution showed at the attached image ("works"); my concern is.. why does my first approach does not work via the IIF clause? ("not work")...
I have a table of raw materials that have two fields, their stock code and longer description.
I have another table that is tracking the usage of these materials. I want both the stock code and longer description to be recorded in the usage table.
I want the "Description" field in the usage table form to auto populate when the user selects the corresponding stockcode from a combobox.
I am trying to use a combobox called Manufacturer to select which table the combobox called Model gets it's rowsource from using the code below.
Code:
Private Sub Manufacturer_AfterUpdate()
If (Me.Manufacturer.Value = "Siemens") Then
Me.Model.RowSourceType = "Table/Query"
Me.Model.Recordset = "SeimensTable"
Me.Model.RowSource = "SELECT Model FROM SeimensTable"
Else
If (Me.Manufacturer.Value = "Samsung") Then
Me.Model.RowSourceType = "Table/Query"
Me.Model.Recordset = "SamsungTable"
Me.Model.RowSource = "SELECT Model FROM SamsungTable"
End If
End If
End Sub
But when I run the form and select Manufacturer. Combobox Model remains empty. tell me what I'm doing wrong?
I have a table that holds the names of locations and a count for each location. example below
LocationCount
INR100
INR16
MTU245
MTU123
INR300
RVO1234
TC45
TC188
The table is always changing and I need to create a query in code that sums the count, grouping for each location. These values will need to be stored in a dynamic array for further processing. How do I store this query value into a dynamic array.
array would need to store these values
(INR, 316)
(MTU, 368)
(RVO, 1234)
(TC, 233)
Thanks in advance
Hey, is there a way to get the full list of tables in the database by using VBA? I am trying to do a backup function, where I want the database to fetch all the table names and put them into an array, to export them one by one to the backup file........hope you guys understands me.....thanks in advance
View 2 Replies View RelatedHow would I modify multiple comboboxes in subforms at the same time. For example.. In main form ComboboxA user selects 1992, Combobox1 in subform1 is also changed to 1992, as well as Combobox2 in subform 2.
Whats the best way to do this?
Hi all,
I have a table with multiple records per individual..
I need to search through all of their results to flag up those in a query that do not match the approved list..
what is the best way to do this?
I am trying a recordset loop but am struggling a bit...
here is my code so far
Private Sub Command0_Click()
Dim rst As DAO.Recordset
Dim dbs As DAO.Database
Dim strSQL As String
Dim strPscale As String
strSQL = "SELECT Eng_Speaking, Eng_speaking from qry_Sub1_crosstab_Crosstab;"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL)
Me.Text1 = ""
Do While Not rst.EOF
strPscale = rst.Fields("Eng_Speaking") & ";"
rst.MoveNext
Loop
Me.Text1 = strPscale
Set rst = Nothing
End Sub
but I need to somehow incorporate an array into this to check the score...
any ideas?
ta
John
I have built the first part of a table analyser into one of my projects as below:
It lists a complete list of tables except system tables for the db being assessed and writes all the table names to a table then the table properties, the fields plus there properties And relasionships and Indexes.
The Idea behind this is When I build a system I always use a frontBack Arrangement and versions within my management system.
there are always two Datafiles one the working datafile where the changes are made during design and the production model used by the users which is the one that will need to be updated by this tool.
The problem I'm having is I don't need to store all the field properties within the tables as a lot wont be used for updating the production model.
So I've been looking at ways I can generate a list of property names that I want stored so when my code loops through the properties list it can before writing the property name and value to the table check it against a list.
My question is would it be better to use an array or enum so I could check for an item and how could I best achieve this as I've not used enums before and I'm not that good at Arrays but there's more help there.
I have in the past used a list like: Prop1,prop2,prop3 which I then check using instr like instr("Prop1") which will return a start position so I know it's in the list but I think this is a bit messy so want to make the improvements
Any help would be much appreciated
mick
Hi, am new here and need a hand
i'm stuck on part of a program where i have a form which has two look-up lists (both looking up names of towns from the same table) and there is also a text box (called distance), which after choosing the town names from the look-up lists, should get the distance between the two towns from the array (in VBA).
thats where i have a problem, for now i have two towns (planning to have probably around 20 maybe more in the future), and something in the array isn't working
below is a link to a zip with that part of the array
i would be really grateful for any help, as i don't have a clue what went wrong
cheers
Hi, totally new on MS access. Is it possible to solve this following task in Access. (using it in Excel today)
Ex.
2d table?
Prod 1 Prod 2 Prod 3
Prod 1 0 10 20
Prod 2 10 0 30
Prod 3 20 30 0
Question 1: What did you just create?
Answer: Prod 1
Question 2: What will you create?
Answer: Prod 3
Then Access will show 30.
Probably explaning it bad but hope you understand and can answer me if this is possible to solve in Access....
The mission is to create a database with setup times between diffrent products, and make it possible to ask a question to get the answer.
/Martin
I have played around with the example from Adam, and wondered how one can make the data output avialable in a form.
I have tried the on click event on a label, but that doesn't work.
I would appreciate any pointers.
I used the 2003 version in this post :
http://www.access-programmers.co.uk/forums/showthread.php?t=142130
I was wondering if this was possible or not.
Can I write a function like the one below, which will accept a value and return many values?
I would like to set various columns from one score. If I have something like “Expr1: returnArray(42)” in the query, can the function return the 3 values and put them in separate columns?
If anyone has any ideas it would be greatly appreciated because I am re-writing my software to have no calculated values.
Public Function returnArray(score As Integer) As Variant
Dim arrMatrix(2) As String
'some calculations here to set the arrMatrix array.
arrMatrix(0) = "Joe"
arrMatrix(1) = "is"
arrMatrix(2) = "Stuck"
returnArray = arrMatrix()
End Function
Hello,
I have a question:
1) Can I use the Array as the field name of Table? For example: Table - ABC, has 3 fields: Value(1), Value(2), Value(3).
2) If not, I define the field names as follows:
Table - ABC, has 3 fields: Value1, Value2, Value3.
Can I use the following states:
For i = 1 to 3
ABC![Value & i] = 100
Next i
Appreciate your help!
Thanks in advanced!
LiBin11011
I have 2 comboboxes, the first one is called "activity", whereby I have 3 options to choose from, and the second is called "level".
When I click an "activity", for example Drawings, I want the "level" combobox to list a unique set of options for that category. and if I click on a different "activity" for example Planning, I want the "level" combobox to show a completely different set of options.
If anyone can give me any help on how to do this then I would be very grateful!!
Thanks
Angela :eek:
Hi all
I'm using an array with the Instr function. The array (or the Instr function) doesn't seem to be case sensitive... which is a pain because its picking words within words where the case doesn't match!! I'd like the vales in the array to match exactly when using the Instr function
Any idea how I can get around this??
Thanks
Damon
Hello Everyone;
Here's my goal: 1) to set up a 7 column table containing a list of 147 numbers from a recordset (StNumberRS) and 2) to compare those numbers to a separate recordset containing a partial list of those numbers (completedStores). If one of the numbers in the completedStores list matches a number on the StNumberRS list show the 'icon_yes.gif' image, otherwise show the 'icon_no.gif'.
I can loop through the StNumberRS and set up the 7 column table, but I'm stuck trying to loop through the completedStores list while inside the StNumberRS loop.
Could someone look through my code and see where I've gone wrong?
Thank you!
Code:<% Dim StoreRS, Query, AltRow, ProjectQuery, ProjectRS, CompletedStores_variable, strValue, CompletedStores_ArrayProjectQuery = "SELECT * FROM Projects WHERE Id =" & Request("Id")Set ProjectRS = Connect.Execute(ProjectQuery)CompletedStores_variable = ProjectRS("CompletedStores") CompletedStores_Array = Split(CompletedStores_variable,",")Dim StNumber_variable, StoreList_ArrayQuery = "SELECT StNumber FROM Stores ORDER BY StNumber"Set StoreRS = Connect.Execute(Query)StNumber_variable = StoreRS("StNumber") StoreList_Array = Split(StNumber_variable,",")%><table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td> <%If Not StoreRS.EOF Then%><!-- Display store list in a table, showing 7 stores in each row: --> <TABLE width="800" cellspacing="0" cellpadding="2"><tr><td colspan="14" align="center" bgcolor="#FFFF00" class="subtitle">PROJECT STATUS</td></tr><tr class="required"> <td>STORE #</td><td>DONE</td><td>STORE #</td><td>DONE</td><td>STORE #</td><td>DONE</td><td>STORE #</td><td>DONE</td><td>STORE #</td><td>DONE</td><td>STORE #</td><td>DONE</td><td>STORE #</td><td>DONE</td></tr><tr bgcolor="#CCCCCC"><td colspan="14"><img src="../images/spacer.gif" width="1" height="1"></td></tr> <% Dim i, theCount, remainder theCount = 0i = 0Do While Not StoreRS.EOF' The StoreList_Array contains 147 numbersFor i = LBound(StoreList_Array) TO UBound(StoreList_Array)' The CompletedStores_Array can vary from zero to 147 elements. Each strValue is one element of the array.'For Each strValue In CompletedStores_Array' As long as theCount equals 7, create an empty row separaating the table rows...remainder = theCount Mod 7If remainder = 0 thenIf theCount <> 0 thenResponse.Write "<tr><td colspan='14'><img src='../images/spacer.gif' width='1' height='1'></td></tr>"Response.Write "<TR>"End IfEnd If'... and create a table row populated with 7 elements from the StoreRS("StNumber"). If StoreRS("StNumber") = CompletedStores_Array(i) Then Response.Write "<TD align='right' valign=top>" & StoreRS("StNumber") & "</td><TD align='center' valign=top><img src='../images/icon_yes.gif' width='13' height='13'></TD>"Else' Output value of current CompletedStores_Array element for debuggingResponse.Write "<TD align='right' valign=top>" & StoreRS("StNumber") & "</td><TD align='center' valign=top><img src='../images/icon_no.gif' width='13' height='13'>" & CompletedStores_Array(i) & "</TD>"End If If remainder = 6 thenResponse.Write "</TR>" & VbCrLfEnd If theCount = theCount + 1i = i + 1StoreRS.MoveNext'next next Loop ' close out the last table row if its not alreadyIf remainder = 0 thenResponse.Write "<TD colspan='12'> </TD></TR>" & VbCrLfEnd If If remainder = 1 thenResponse.Write "<TD> </TD></TR>" & VbCrLfEnd If%> </TABLE> <%Else Response.Write "<p>There currently is no data for this project.</p>"End If%> </td> </tr></table>
I've built a query that selects certain customers based on a purchase date. I now need to assign these customers to various sales reps and display the customer information to them in another form that they can alter information in.
I was going to put my sales reps id into an array and loop it through the query updating it. Let's say i have 7 sales reps working that day, I would then enter their id's into fields and have the array assign these numbers into the query Sales Rep Id field for each row.
I reviewed a few ways to rank based on calculations and use them, however what I'm looking to accomplish is subjective ranking whilst limited the ranks to the total number of records in the recordset.
e.g. you have 50 records. Manually moving Record # 30 up to #3 would bump the existing records #3 to #29 down one (to #'s 4 through 30) and records >30 would stay the same.
Would deploy this to the end users within a continuous form, each row having Up/Down arrows to move each record up/down 1 rank as well as provide a combo box so they may choose any value within the array they want to set it to...
Anyone know if Access 2007 has control arrays or some thing similar?
Thanks
Hi, I have a problem deleting a specific row and field that my query have.
What I want to do is mainly delete a specific rows in the my Query table that has : Field 1, Field 2, Field 3, Field4
what i tried to do was doing is create and array that loop through the Query table and check in field 1 for a certain value and if that certain value appears I want to delete that row: for example
Dim IntRow As Integer
Dim IntCol As Integer
Dim varData As Variant
For IntCol = 0 To numFields Step 1
For IntRow = 0 To numRows Step 1
If (rst.EOF = False) Then
'Check Field 1 for value 47-72 to delete
Else
If (varData(0,IntRow) > 47 And varData(0,IntRow) < 72) Then
varData(IntCol, IntRow).Delete
End If
End If
Next IntRow
Next IntCol
In the example Above my syntax is not correct for :
If (varData(0,IntRow) > 47 And varData(0,IntRow) < 72)
and for varData(IntCol, IntRow).Delete.
can anyone help me to find the exact syntax i need to use to execute the program above?
THANK YOU!
I'm populating a combo box from a query. I'm running a DCount on 2 criteria. The user selects the criteria from 2 combo boxes. If the user types * into the combo box, I want to be able to loop through each combination from the combo box values. I need to get the list of values from the combo box and put it into a string array, however it throws a type mismatch if I did something like
BRANCHES(x)=CStr(cboBranches(x)) 'cboBranches(x)=cboBranches.Value(x)
So I tried to run the sql from vb but found out that I can't return a string value from that (vb sucks). So I'm back to trying to get the values from the combo box. Any help would be appreciated.
Hello,
I wanted to catch a little advice if I may be so bold. I have a HTML form with a series of checkbox values.
Code:<form method=post action=form-test.asp><input type=checkbox name=drinks value='cocal-cola'>cocal-cola<input type=checkbox name=drinks value='sprite'>sprite'<input type=checkbox name=drinks value='lucozade'>lucozade<input type=checkbox name=drinks value='oasis'>oasis<input type=submit value='Submit'></form>
Normally I would gather these up into an array using ASP and email the split up comma separated values out to the client via an email.
Code:drinks=Request("drinks")drinks_split=split(drinks,",")'email drinks to client
However, this time I need to store those values in an access database. I am assuming that the client may want to run queries on the different array values, for example, how may people chose coca cola and sprite.
Is it better to store the value separately - one Ms access field for coca cola, one for sprite (which is what I thought I would have to do to create queries on this) - or can they be stored under one field heading "drinks" and queries be performed on different values within that field?
Could someone explain a quick way of doing the latter i possible in MS access and the SQL for querying?
Cheers,
trufla