Dear all,
I am about to learn MS Access using VBA. Currently I am trying to figure out how Loops etc. are working. The book I bought does not tell me a lot about this topic and I am wondering whether anyone could help me on the following. I a basically want to Loop throug a query (or if not possible trough a table) and show the results in my form. For each record in the table I am doing additional checks when loading the form and showing that result accordingly. I do not want to do these checks in additional queries - I think it is more efficient doing it in the form directly. Here is the code I have:
Dim dbsSR As DAO.Database
Dim rstValQry As DAO.Recordset
Set dbsSR = CurrentDb
Set rstValQry = dbsSR.OpenRecordset("qry_val_tbl_ind_rec-rev_import")
With rstValQry
While (Not .EOF)
strCieVal = Me![ValComp] & ";"
strAcctVal = Me![ValAcct] & ";"
If strPCAct = -1 Then
strPCVal = Me![ValPC] & ";"
Else
strPCVal = ""
End If
If strBAAct = -1 Then
strBAVal = Me![ValBA] & ";"
Else
strBAVal = ""
End If
If strLocAct = -1 Then
strLocVal = Me![ValLoc] & ";"
Else
strLocVal = ""
End If
'***** combine individual errors into one error message (for the ones which are relevant / active) *****
strErrSum = strCieVal & strAcctVal & strPCVal & strBAVal & strLocVal
Me![ErrSum] = strErrSum
.MoveNext
Wend
.Close
End With
The Loop seems to work because in debug it is going through it 3 times (the number of records I have in the query), but the result is always the same - it seems the above code is not checking / refreshing based on the individual query records.
What am I doing wrong?
I am about to learn MS Access using VBA. Currently I am trying to figure out how Loops etc. are working. The book I bought does not tell me a lot about this topic and I am wondering whether anyone could help me on the following. I a basically want to Loop throug a query (or if not possible trough a table) and show the results in my form. For each record in the table I am doing additional checks when loading the form and showing that result accordingly. I do not want to do these checks in additional queries - I think it is more efficient doing it in the form directly. Here is the code I have:
Dim dbsSR As DAO.Database
Dim rstValQry As DAO.Recordset
Set dbsSR = CurrentDb
Set rstValQry = dbsSR.OpenRecordset("qry_val_tbl_ind_rec-rev_import")
With rstValQry
While (Not .EOF)
strCieVal = Me![ValComp] & ";"
strAcctVal = Me![ValAcct] & ";"
If strPCAct = -1 Then
strPCVal = Me![ValPC] & ";"
Else
strPCVal = ""
End If
If strBAAct = -1 Then
strBAVal = Me![ValBA] & ";"
Else
strBAVal = ""
End If
If strLocAct = -1 Then
strLocVal = Me![ValLoc] & ";"
Else
strLocVal = ""
End If
'***** combine individual errors into one error message (for the ones which are relevant / active) *****
strErrSum = strCieVal & strAcctVal & strPCVal & strBAVal & strLocVal
Me![ErrSum] = strErrSum
.MoveNext
Wend
.Close
End With
The Loop seems to work because in debug it is going through it 3 times (the number of records I have in the query), but the result is always the same - it seems the above code is not checking / refreshing based on the individual query records.
What am I doing wrong?