Hi all
I was wondering if you could guide me in the right direction....else, I might tear my hair out!
ok, I have a form, with a subform. Based on 2 fields on the subform, I refresh the results in the subform.
These fields are:
CBOclientYTD:
CBOfiscal:
on update event (for both fields) I run the following VBA:
the problem is, when I select a client name from the drop down or a fiscal year from the drop down, or both, the first record in the table is updated to the value in the cboClientYTD field.
so, if record 1 client = 20, and I filter the records to show only those for client 30, it will display all the correct records,but in the background it updates record 1 client to 30....
I cant figure it out
I was wondering if you could guide me in the right direction....else, I might tear my hair out!
ok, I have a form, with a subform. Based on 2 fields on the subform, I refresh the results in the subform.
These fields are:
CBOclientYTD:
Code:
SELECT tblClients.ID, tblClients.Client FROM tblClients;
Code:
SELECT (Year(DateAdd("m",6,tblMargin.Week))) AS Fiscal
FROM tblMargin
GROUP BY (Year(DateAdd("m",6,tblMargin.Week)));
on update event (for both fields) I run the following VBA:
Code:
Dim strSQL As String
Client = Me.cboClientYTD
Fiscal = Me.cboFiscal
If IsNull(Fiscal) And IsNull(Client) Then
where = ""
Else
If Not IsNull(Client) And IsNull(Fiscal) Then
where = " WHERE tblMargin.client = " & Client
Else
If IsNull(Client) And Not IsNull(Fiscal) Then
where = " WHERE Year(DateAdd('m',6,tblMargin.Week)) = " & Fiscal
Else
If Not IsNull(Client) And Not IsNull(Fiscal) Then
where = " WHERE Year(DateAdd('m',6,tblMargin.Week)) = " & Fiscal & " AND tblMargin.client = " & Client
End If
End If
End If
End If
strSQL = "SELECT Year(DateAdd('m',6,tblMargin.Week)) AS Fiscal, tblClients.Client, sum(tblMargin.Hours) AS SumOfHours, Sum(tblMargin.Income) As SumOfIncome, Sum(tblMargin.wAGES) AS SumOfwAGES, Sum(tblMargin.Super) AS SumOfSuper"
strSQL = strSQL & " FROM tblClients LEFT JOIN tblMargin ON tblClients.ID = tblMargin.Client"
strSQL = strSQL & where
strSQL = strSQL & " GROUP BY Year(DateAdd('m',6,tblMargin.Week)), tblClients.Client"
strSQL = strSQL & " ORDER BY Year(DateAdd('m',6,tblMargin.Week)), tblClients.Client"
'MsgBox Fiscal
'MsgBox Client
Form_qryMarginYTD.RecordSource = strSQL
the problem is, when I select a client name from the drop down or a fiscal year from the drop down, or both, the first record in the table is updated to the value in the cboClientYTD field.
so, if record 1 client = 20, and I filter the records to show only those for client 30, it will display all the correct records,but in the background it updates record 1 client to 30....
I cant figure it out