looping through fields record
RH

Forum home » Delegate support and help forum » Microsoft Access VBA Training and help » Looping through fields in a record set

Looping through fields in a record set

resolvedResolved · High Priority · Version 2016

Manny has attended:
Access Intermediate course
Access Advanced course

Looping through fields in a record set

Hi Guy,

Hopefully an easy one compared the others i have posted.

This is a bank account reconciliation. A user would have selected transactions that they want to match off (these are then stored in a temporary table). Once the user is happy with the transactions they have selected, they have the ability to then "confirm" and match transactions (to which point they move to matched status and removed from temp table).

My problem exists when the user confirms the match. I would like to run some controls to ensure all the essential data does in fact match. for example, I want to loop through all the records in the table and confirm all the fields match (exception of the amount). For example loop through all the records and see if the "Transaction Date", match in the table.

I have constructed the loop but unsure how to compare all the records to each other? Please may you show me how one would construct this this to compare all the records do actually match.


Set InfoRST = dbs.OpenRecordset(strSQL)
If Not (InfoRST.EOF And InfoRST.BOF) Then
InfoRST.MoveFirst
Do Until InfoRST.EOF = True

{INSERT COMPARISON CODE HERE}

{INSERT COMPARISON CODE HERE}

'Move to the next record.
InfoRST.MoveNext
Loop
End If




RE: Looping through fields in a record set

Hi Manny,

Thank you for the forum question.

I would never do this with VBA. A simple query should be able to do
this and a unmatch query will find all without a match.

If you add the two tables to a query and the create a query relationship between the two field you want to compare.

Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Looping through fields in a record set

Hi Jens,

Sure, that makes sense, all the records are in one table though? Can still run the query on the same table to compare the fields of each record?

Manny

RE: Looping through fields in a record set

Hi Manny,

If they are in one table how do you identify the records you want to match? I assume that you have more than one transaction a day.

I would organise the records in two tables. You can create a MAKE TABLE/APPEND query to split the data in two tables and then make a query relationship between the two tables to find the match.

It can be totally automated.


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Looping through fields in a record set

Hi Jens,

I took your approach on the simple query. if i just count the unique records (it should be 1 if the date matches) then contiune otherwise, it will alert the user.

Manny

'check if value date matches
strSQL = "SELECT tbl_InformationScreenByFund.ValueDate FROM tbl_InformationScreenByFund GROUP BY tbl_InformationScreenByFund.ValueDate"
Set InfoRST = dbs.OpenRecordset(strSQL)
If InfoRST.RecordCount > 1 Then
If MsgBox("WARNING: Value Date Mismatch" & vbCrLf & _
"Would user like to cancel match?", vbYesNo, "Value Date Mismatched") = vbYes Then
Exit Sub
Else: Comm = "Mismatch Value Date"
End If
Exit Sub
End If

RE: Looping through fields in a record set

Again well done Manny


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Thu 23 May 2019: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Access tip:

Space marks

It is good practice not i to have space marks for field names as this can lead to problems when using queries or VBA code. It is much better to use an underscore charcter to represent spaces in field names

View all Access hints and tips


Server loaded in 0.06 secs.