tags:

views:

130

answers:

3

i am a vb.net programmer, and i have done lots of VBA with excel. i am a beginner at access.

someone has given me an access database to debug and i am lost.

i succesfully made it connect to a local mysql database.

i have a listbox on a form that has a rowsource attached to a query called listbox. here's a picture of the properties of the listbox: alt text

there are some issues with displaying the results of the query because the query is too complex and incorrectly structured. when there are fewer than a few results from the query, they display in the listbox without a problem, but when there are more than 4-5 results, it leaves it blank; however, i know that it returned the correct number because it left the correct number of rows (which are blank in the listbox). therefore, instead of trying to fix the huge messy query, i would like to feed all the rows in a string, and then feed them back into the listbox.

can someone help me with this? when you reply please put your responses in laymen's terms because as i said i am an access beginner.

this is what the listbox looks like when it doesnt want to display results: alt text

A: 

If you're using ADO then you can use the .GetRows method to put the recordset into a two-dimensional array (matrix) and then manipulate it. Of course it'd be better if you could simplify your query so that Access would work normally with it.

Lance Roberts
how do i find out whether i am using ADO? im sorry im a beginner at access
I__
Well, you could check the references like you would in Excel, but I'd probably just try to assign the result of the .GetRows method to a Variant array, and see what happens.
Lance Roberts
lance, FYI i NEVER mark anyone down for trying to help me, so it was not me who marked you down
I__
I didn't figure you did. It's probably just some people who haven't had to work all the time with VBA as I have.
Lance Roberts
I voted your answer down because it's leading him down the garden path in a direction that overcomplicates things. It may be relevant to the question he asked, but it's not going to be relevant to the best SOLUTION. And I program in VBA in Access every day, and have been doing so professionally since VBA was introduced into MS Office in 1995-96.
David-W-Fenton
+1  A: 

I'm wondering if the Column Count property is correct. That is are there ten columns or fields in the query?

Also you should really put ten widths in the Column Widths property even if they are 0" width. I only see seven in there.

Is this Access 2003 with SP3? If so see this KB article. Combo box controls and list box controls display no value or incorrect values in Access 2003 after you install Office 2003 Service Pack 3

Tony Toews
how do i find out which SP version it is?
I__
by the way ive updated my question, please look at the last graphic
I__
Check the 'About' link in the 'Help' Menu.
Lance Roberts
Your last graphic doesn't tell us anything. Have you checked the items I've listed in my posting?
Tony Toews
+1  A: 

You could try something on these lines:

''Some notes on declarations for ADO recpdset and connection
Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection

''Set the connection object to the access project
''connection. You may wish to use a connection string (see below)
Set cn = CurrentProject.Connection

''Open the recordset, change the sql string to whatever string is used
''to populate the listbox
rs.Open "SELECT * FROM Testaccess", cn

''Convert the recordset to a string delimited by row and column with ;
''This is the delimiter needed by Access for the listbox with value data
strlist = rs.GetString(, , ";", ";")

''Set the rowsource of the listbox to the string
Me.List0.RowSource = strlist

''It would be easiest to set these before the run
''None of this is necessary, it can all be set as properties 
''of the listbox before the code is run
''Column count, same as number of fields
Me.List0.ColumnCount = rs.Fields.Count
''List type is values
Me.List0.RowSourceType = "Value List"

''This is just a set of 1cms for each column
For i = 1 To rs.Fields.Count
    strWidths = strWidths & ";1cm"
Next

''here we go, all columns set to 1cm width
Me.List0.ColumnWidths = Mid(strWidths, 2)

connection string: http://www.connectionstrings.com/

Remou
rs.Open "SELECT users.id, users.first, users.last, chavrusas.luser_type AS user_type, chavrusas.id, users.title, users.city, users.state, users.home_phone, users.email FROM Users INNER JOIN chavrusas ON Users.id=chavrusas.luser_id WHERE ((chavrusas.ruser_id)=id_txt and chavrusas.ended=false) AND (chavrusas.luser_type)<>(chavrusas.ruser_type) AND NOT ((chavrusas.luser_type)='teacher' AND (chavrusas.ruser_type)='student') AND NOT ((chavrusas.ruser_type)='teacher' AND (chavrusas.luser_type)='student'); UNION SELECT users.id, users.first,et cetcetc ..... "no value given on one of the parameters"
I__
the only thing i can do is copy and paste that code, i dont know what anything means so you will have to simplify it and provide clear instructions for every line
I__
No value given for one or more required parameter is probably from the Where statement. If you refer to a form, keep it outside the quotes. Please post the full SQL in your post if you need help with it.
Remou
Remou, nothing personal but yikes this is an ugly solution when it should just work.
Tony Toews
Tony Toews, the op says"i would like to feed all the rows in a string, and then feed them back into the listbox" and sometimes I give people what they ask for, and let them decide whether it is a good idea or not.
Remou
After all, that is the line that makes this question different from other listbox questions and Stackoverflow is not a forum, it is a question and answer site.
Remou
Remou, the OP is wrong. He/she should be figuring out what the real problem is instead of masking it.
Tony Toews
I am not sure that we would have got the information that the SQL is not working so quickly without this step. Sometimes it is necessary to take a slightly longer road.
Remou
Listboxes do not tell you that the SQL does not work.
Remou
I'm with Tony on this one. I also question why someone has 10 columns in a listbox. I've occasionally used a listbox like a subform, but when you've got more than 5 or 6 columns, it seems to me like it's no longer really a list at all, but a data display control, and probably should be a subform.
David-W-Fenton
david and tony, i really appreciate your responses; however, if you know the answer to my question please help!
I__
Nobody can answer your question without seeing the full SQL of your listbox's rowsource, which you seem reluctant to post. There's no guarantee we can solve the problem with the SQL, but without it, it's impossible (unless someone just happens to guess the correct answer).
David-W-Fenton
I've already answered your questions but you haven't stated that you've checked them. That is the hoftix and check the number of columns.
Tony Toews
Remou, the OP stated "it is displaying 3 results ". That tells me his query is working.
Tony Toews
tony i did check the number of columns
I__
Ok, so respond accordingly to my posting. And what about the missing column widths and the hotfix? Did you check those?
Tony Toews