I am quite new to this VBA stuff and I have actuallty posted this question in another area but it seems very complicated the way I 1st posted it.
I have written the following code:
*******
Private Sub Command0_Click()
Dim strSQL As String
Dim strOldSQL As String
Dim txtDeptNo As String
Dim intDepNoCount As Integer
txtDeptNo = DLookup("[PRFT CNTRE]", "Department", "REPORTFUNCT = 'BalanceSheet'"
Debug.Print txtDeptNo
DoCmd.SetWarnings False
strSQL = "UPDATE DISTINCTROW cc SET cc.[Cost Centre]='" & txtDeptNo & "'"
'change the sql property of the query "qselMyQuery"
strOldSQL = ChangeSQL("010", strSQL)
'your query will now have a new sql value
DoCmd.OpenQuery "010", acViewNormal, acEdit
DoCmd.OpenQuery "BudControlTestcreate", acViewNormal, acEdit
DoCmd.OpenReport "BudCntrlTTEST", acPreview
DoCmd.SetWarnings True
Debug.Print strSQL
End Sub
********
This is working fine but I have to run this for each [PRFT CNTRE] that fits the criteria. As it is text I cannot simply add 1 to it. I somehow need to move onto the next [PRFT CNTRE] that has a REPORTFUNCT = 'BalanceSheet' until there are no more. (I will have other criteria later).
Cheers.
I have written the following code:
*******
Private Sub Command0_Click()
Dim strSQL As String
Dim strOldSQL As String
Dim txtDeptNo As String
Dim intDepNoCount As Integer
txtDeptNo = DLookup("[PRFT CNTRE]", "Department", "REPORTFUNCT = 'BalanceSheet'"
Debug.Print txtDeptNo
DoCmd.SetWarnings False
strSQL = "UPDATE DISTINCTROW cc SET cc.[Cost Centre]='" & txtDeptNo & "'"
'change the sql property of the query "qselMyQuery"
strOldSQL = ChangeSQL("010", strSQL)
'your query will now have a new sql value
DoCmd.OpenQuery "010", acViewNormal, acEdit
DoCmd.OpenQuery "BudControlTestcreate", acViewNormal, acEdit
DoCmd.OpenReport "BudCntrlTTEST", acPreview
DoCmd.SetWarnings True
Debug.Print strSQL
End Sub
********
This is working fine but I have to run this for each [PRFT CNTRE] that fits the criteria. As it is text I cannot simply add 1 to it. I somehow need to move onto the next [PRFT CNTRE] that has a REPORTFUNCT = 'BalanceSheet' until there are no more. (I will have other criteria later).
Cheers.