PDA

View Full Version : Solved: Passing variables



mikekay
05-27-2010, 12:29 PM
I spent literally a whole day trying to figure this out and nothing. I hate asking for help because of flaming etc... but here it is please help me out

WHAT THE HELL AM I DOING WRONG, I've tried every variation of the code I could.

SEARCH FORM
Private Sub cmdSearch_Click()
Dim LSQL As String
x = cboSearchField.Value
y = txtSearchString.Value

If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
MsgBox "You must select a field to search."

ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
MsgBox "You must enter a search string."

Else

'Generate search criteria
GCriteria = "MainDB.[" & x & "]=" & "'" & y & "'"


'Filter frmCustomers based on search criteria
Form_Master.RecordSource = "select * from MainDB where " & GCriteria
Form_Master.Label21.ForeColor = vbRed
Form_Master.Label21.Caption = "Filter: " & x & " Contains " & y

'Close frmSearch
GCriteria = Form_Master.OldGCriteria
DoCmd.Close acForm, "frmSearch"

MsgBox "Results have been filtered."

If Form_Master.RecordsetClone.RecordCount = 0 Then
MsgBox "The search returned 0 results!"
Form_Master.Label21.ForeColor = "1031513"
Form_Master.Label21.Caption = "No Filter Applied"



'Clear criteria
GCriteria = ""

'Display all customers
LSQL = "select * from MainDB"
Form_Master.RecordSource = LSQL

End If
End If


MASTER FORM

Option Compare Database
Public OldGCriteria

Private Sub Command30_Click()
End Sub

Private Sub Combo46_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub Combo46_Change()
IsActiveValue = Combo46.Value

If Len(OldGCriteria) = "0" Or IsNull(OldGCriteria) = True Then

If IsActiveValue = "Yes" Then
'Generate search criteria
ACriteria = "MainDB.[IsActive]=-1"

'Filter frmCustomers based on search criteria
Form_Master.RecordSource = "select * from MainDB where " & ACriteria
Form_Master.Label49.ForeColor = vbRed
Form_Master.Label49.Caption = "Active Only? " & OldGCriteria
Else
'Generate search criteria
ACriteria = "MainDB.[IsActive]=0"


'Filter frmCustomers based on search criteria
Form_Master.RecordSource = "select * from MainDB where " & ACriteria
Form_Master.Label49.ForeColor = "1031513"
Form_Master.Label49.Caption = "Active Only? " & OldGCriteria

End If

End If
If Len(OldGCriteria) > 0 Then

If IsActiveValue = "Yes" Then
'Generate search criteria
ACriteria = "MainDB.[IsActive]=-1"


'Filter frmCustomers based on search criteria
Form_Master.RecordSource = "select * from MainDB where " & OldGCriteria & " AND " & ACriteria
Form_Master.Label49.ForeColor = vbRed
Form_Master.Label49.Caption = "Active Only? " & OldGCriteria
Else
'Generate search criteria
ACriteria = "MainDB.[IsActive]=0"


'Filter frmCustomers based on search criteria
Form_Master.RecordSource = "select * from MainDB where " & OldGCriteria & " AND " & ACriteria
Form_Master.Label49.ForeColor = "1031513"
Form_Master.Label49.Caption = "Active Only? " & OldGCriteria

End If

End If
End Sub

Bob Phillips
05-27-2010, 02:40 PM
It might help if you gave us a clue, what is it not doing, doing wrongly, supposed to do?

mikekay
05-28-2010, 04:39 AM
Im sorry. Ok so Im trying to pass the GCriteria Variable from Form_frmSearch to Form_Master. but every time it comes up blank. I want to pass the variable before I close the search form but it always empty. Help?!

OBP
05-28-2010, 10:08 AM
That looks a very complicated bit of code just to pass a variable to another form.
Are you aware of the OpenArgs function?
Or setting the form's filter?
Or setting the forms Query Criteria Row?

mikekay
05-28-2010, 10:15 AM
I figured it out all I did was create a textbox on the master, through the variable there before frmsearch closed. Made it invisible and locked it. and read the variable on the master form.

Thanks for trying guys!

Ill be back thats for sure. :/