|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
RowSource Problems
I'm using VBA to dynamically write an SQL query which then forms the query for a RowSource within a list box. The SQL is generated by the user choosing a couple of options via some combo boxes. These options are placed into an SQL statement which is then used to generate the contents of a list box.
Several times I have written the code and it seems to work fine for a short period but then suddenly stops working. When it stops the RowSource in the list box just doesn't change anymore - it seems to freeze at a particular set of values. Up to the point of 'freezing' the whole thing has worked fine. Can anyone suggest what might be going wrong - or what I need to check? I know the SQL is OK and is being formed correctly since I use a debug MSgBox to see what is being created. But for some reason the list box just doesn't seem to pick up any changes being made to the SQL All help so gratefully recieved - this is really causing me a headache. Thanks, Neil |
|
#2
|
|||
|
|||
|
Need more
Can you post the code/statement?
|
|
#3
|
|||
|
|||
|
Here is the code I am using in the first form. I have left out the first part where I 'dim' the variables etc..
It will also be obvious that I am new to this game - but please don't be too critical - I am trying! Code:
StaffName = Me.cboMathsStaff.Value
If StaffName = "All" Then
StaffName = "Like '*'"
Else: StaffName = " = '" & StaffName & "'"
End If
Course = Me.cboCourse.Value
If Course = "All" Then
Course = "Like '*'"
Else: Course = " = '" & Course & "'"
End If
Group = Me.cboBlock.Value
If Group = "All" Then
Group = "Like '*'"
Else: Group = " = '" & Group & "'"
End If
SearchCriteria = "MathsStaff " & StaffName & " AND Level " & Course & " AND Block " & Group & ""
strSQL = "SELECT tblRecords.ID, tblRecords.FirstName, tblRecords.Surname " & _
"FROM tblRecords " & _
"WHERE tblRecords.MathsStaff " & StaffName & " AND tblRecords.Level " & Course & " " & _
"AND tblRecords.Block " & Group & " " & _
"ORDER BY tblRecords.Surname;"
Form_frmRecords.lstStudents.RowSource = strSQL
DoCmd.OpenForm "frmRecords", , , SearchCriteria, acFormEdit
Thanks again, Neil |
|
#4
|
|||
|
|||
|
....does this help?
I have found one thing that will always cause the problem.
When I shut down the application it asks if I want to save changes made to the form? Regardless of how I reply the two forms don't work 'correctly' when I run Access again. However if I play around with the code - eg insert REM marks against the code, then delete them again, it all starts working again! Does this make any sense? Neil |
|
#5
|
|||
|
|||
|
Thanks to anyone who gave this problem brain time. I have now managed to resolve the issue by approaching it from a different angle.
Instead of trying to sqiurt the data directly into the RowSource I open a query using SQL which allows me to put in the variables I need. Then I point the list box to the query. This works no matter what I do to the data. Only one thing though - when I open the form with the target list box it contains old data ie data from the previous time the query was run. If I want to view the records from the latest run of the query I have to refresh the form, which I do by pressing a refresh button. Is there a way to auto refresh the list? I know I'm not very experienced in these matters but I do find it fun - and slowly I'm learning, so all help gratefully appreciated. Thanks, Neil |
|
#6
|
|||
|
|||
|
use the "RepaintObject" command at the end of the macro if you are using a macro. It has been a while since I used this option. after the "RepaintObject" is selected, at the bottom of the screen you will find a text box "Object type". choose "Form" for this box and for "Object Name" choose the form you wish to refresh
Good luck |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > RowSource Problems |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|