Not sure if this is a query issue, or a form issue.
I've been using a Listbox as a search result window. Edit fields and buttons, user enters criteria, hits button and listbox is populated with query results. A form is generated when the user double clicks on a row item in the listbox.
I've added some new code, and for some reason, when the form loads, it is missing all the data.
The 'old' buttons still work perfect, the 'new' buttons don't load anything in the form.
I basically copied and pasted the buttons from the old code, and edited some values, but the basics are still in place.
This is driving me nuts, seems so simple. This is the code we use to load the new form
Code:
Public Sub List0_DblClick(Cancel As Integer)
On Error GoTo Err_List0_DblClick
Dim stLinkCriteria As String
Dim stdocname As String
stdocname = "Combo"
'MsgBox strSQL
If CurrentProject.AllForms(stdocname).IsLoaded Then
MsgBox "The form you are attempting to open is already open." & _
vbNewLine & "Please save what you are working on then" & _
vbNewLine & "close the form. Then try this operation again.", vbOKOnly, "Form Already Open"
Else
stLinkCriteria = "[ID]=" & Me!
[List0]
If IsNull(Me!
[List0]) = False Then
If Me!
[List0] <> 0 Then
DoCmd.OpenForm stdocname, , , stLinkCriteria
Else
MsgBox "Please select an account", vbOKOnly, "WARNING!"
End If
End If
End If
Exit_List0_DblClick:
Exit Sub
Err_List0_DblClick:
Response = MsgBox("Please select an account", vbOKOnly, "WARNING!", "DEMO.HLP", 1000)
Resume Exit_List0_DblClick
End Sub
And this is some sample OLD button code(some redaction)
Code:
Public Sub SrchByAddr2_Click()
stdocname = "COMBO"
Me!
[List0] = "0"
Me.List0.RowSource = "SELECT [Main].[ProjectID], [Main].[Status], [Main].[ffff], [Main].[ffff], [Main].[SlsMgr], [Main].[ProjNme], [Main].[PTD], [Main].[Addr1], [Main].[Addr2], [Main].[City], [Main].ID FROM [Main] where [Main].[Addr2] like " & "'*" & Me!ProjectID & "*'" & "ORDER BY [ProjectID] DESC;"
End Sub
Private Sub SrchByProjName_Click()
stdocname = "COMBO"
Me!
[List0] = "0"
Me.List0.RowSource = "SELECT [Main].[ProjectID], [Main].[Status], [Main].[ffff], [Main].[fffff], [Main].[SlsMgr], [Main].[ProjNme], [Main].[PTD], [Main].[Addr1], [Main].[Addr2], [Main].[City], [Main].ID FROM [Main] where [Main].[ProjNme] like " & "'*" & Me!ProjectID & "*'" & "ORDER BY [ProjectID] DESC;"
End Sub
And the new:
Code:
Private Sub Search2_Click()
stdocname = "COMBO"
WhereDone = False
strSQL = "SELECT ProjectID, Status, ffff, fffff, SlsMgr, ProjNme, PTD, Addr1, Addr2, City, FDRet, ID FROM [Main]"
If (Check62 = False) And (Check64 = False) And (Check66 = False) And (Check68 = False) And (Check80 = False) And (Check82 = False) And (Check84 = False) And (Check86 = False) Then
MsgBox "Please select a search filter", vbOKOnly, "Notice:"
Exit Sub
End If
If (Check80 = True) Then
If WhereDone Then
strSQL = strSQL & " or "
Else
strSQL = strSQL & " WHERE ("
WhereDone = True
End If
strSQL = strSQL & "Status = 'In process' "
End If
If (Check86 = True) Then
If WhereDone Then
strSQL = strSQL & " or " 'or
Else
strSQL = strSQL & " WHERE (FDret Is Null) and ("
WhereDone = True
End If
strSQL = strSQL & "Status = 'In process' "
End If
If (Check84 = True) Then
If WhereDone Then
strSQL = strSQL & " or " 'or
Else
strSQL = strSQL & " WHERE ("
WhereDone = True
End If
strSQL = strSQL & "Status = 'aaaaaProgress' "
End If
If (Check82 = True) Then 'with rep
If WhereDone Then
strSQL = strSQL & " or " 'or
Else
strSQL = strSQL & " WHERE ("
WhereDone = True
End If
strSQL = strSQL & "Status = 'with rep' "
End If
If (Check68 = True) Then '''ALL
If WhereDone Then
strSQL = strSQL & " and "
Else
strSQL = strSQL & " WHERE ("
WhereDone = True
End If
strSQL = strSQL & "[Main].[ProjectID] like " & "'*" & Me!ProjectID & "*'" '& ")"
End If
If (Text78 > "") Then 'if NOT blank
If WhenDone Then
strSQL = strSQL & " and Staff = '" & Me!Text78 & "' "
Else
strSQL = strSQL & ") and ( "
WhereDone = True
End If
strSQL = strSQL & "[Main].[staff] like " & "'*" & Me!Text78 & "*' "
End If
If WhereDone Then
strSQL = strSQL & ") and ([Main].[ProjectID] like " & "'*" & Me!ProjectID & "*'" & ") "
'strSQL = strSQL & ") "
End If
' order by project
strSQL = strSQL & "ORDER BY [ProjectID] DESC;"
'MsgBox strSQL ' Uncomment to Display SQL for testing
' set the rowsource for the listbox and then requery
Me!
[List0] = "0"
Me.List0.RowSourceType = "Table/Query"
Me.List0.RowSource = strSQL
Me.List0.Requery
End Sub
Any thoughts?