G
Guest
I need to streamline some SQL code. Here's what I envision.
- Create a generic (static) function such as ListboxRowSource()
- Have several OnClick events... each of them may have an IF/ELSE statement
or several CASE statements... in this case I used the IF/THEN approach
- Given a specific OnClick event and its matching IF criteria, I'd call the
SQL from the ListBoxRowSource function and tag on the proper ORDER criteria
Currently, the way I wrote the code, I get a syntax error. It indicates
the error is: "Compile error. Expected array."
What am I missing?
Tom
++++++++++++++
Function ListboxRowSource() as string
dim ssql as string
ssql = "SELECT Field1, Field2 FROM TableName WHERE..." & vbcrlf
ListBoxRowSource = ssql
End Function
++++++++++++++
Private Sub Control_A_Click()
Dim ssql As String
If Me.Control_A.Caption = "A"
Me.Listbox1.rowsource = ListboxRowSource() + "ORDER BY
Field1"
Else
Me.Listbox1.rowsource = ListboxRowSource() + "ORDER BY
Field2"
End If
End Sub
++++++++++++++
Private Sub Control_B_Click()
Dim ssql As String
If Me.Control_B.Caption = "B"
Me.Listbox1.rowsource = ListboxRowSource() + "ORDER BY
Field3"
Else
Me.Listbox1.rowsource = ListboxRowSource() + "ORDER BY
Field4"
End If
End Sub
++++++++++++++
- Create a generic (static) function such as ListboxRowSource()
- Have several OnClick events... each of them may have an IF/ELSE statement
or several CASE statements... in this case I used the IF/THEN approach
- Given a specific OnClick event and its matching IF criteria, I'd call the
SQL from the ListBoxRowSource function and tag on the proper ORDER criteria
Currently, the way I wrote the code, I get a syntax error. It indicates
the error is: "Compile error. Expected array."
What am I missing?
Tom
++++++++++++++
Function ListboxRowSource() as string
dim ssql as string
ssql = "SELECT Field1, Field2 FROM TableName WHERE..." & vbcrlf
ListBoxRowSource = ssql
End Function
++++++++++++++
Private Sub Control_A_Click()
Dim ssql As String
If Me.Control_A.Caption = "A"
Me.Listbox1.rowsource = ListboxRowSource() + "ORDER BY
Field1"
Else
Me.Listbox1.rowsource = ListboxRowSource() + "ORDER BY
Field2"
End If
End Sub
++++++++++++++
Private Sub Control_B_Click()
Dim ssql As String
If Me.Control_B.Caption = "B"
Me.Listbox1.rowsource = ListboxRowSource() + "ORDER BY
Field3"
Else
Me.Listbox1.rowsource = ListboxRowSource() + "ORDER BY
Field4"
End If
End Sub
++++++++++++++