Problem with Looping records (1 Viewer)

urjudo

Member
Local time
Today, 16:55
Joined
Oct 9, 2020
Messages
67
Hello,
I'm working on Save a batch reports to pdf individual(with the tagno). Everything seems working however if I have the IF statement then it's not loop through all the records, I have a If statement like
If Me.Salvage = True then
do this
else
do this
End if

This If statement doesn't matter the condition is True/false or if the condition is a text, it still not loop through the records. I can't figure it out how to do it. Any help would be great appreciate!

Attached is my database . The criteria is BeginDate: 1/1/18
EndDate: 12/31/18
Clasee: Property
 

Attachments

  • SaveReports.accdb
    604 KB · Views: 257

Gasman

Enthusiastic Amateur
Local time
Today, 22:55
Joined
Sep 21, 2011
Messages
14,343
Not even sure what it is meant to do, but I produce 20 files when the control said 10, but that appears to be 10 of A and 10 of B?

You need to be a little more descriptive of what it is not doing?

Walk through the code with F8 after setting a breakpoint.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 22:55
Joined
Jul 9, 2003
Messages
16,285
I answered a similar question on access world forums a while back.

You can see the solution on my website here:-

 

urjudo

Member
Local time
Today, 16:55
Joined
Oct 9, 2020
Messages
67
@Gasman,
What I'm doing on the reports is, if the Salvage is true in the record(s) then it should have the report name as Salvage A & Salvage B, if it's false the it should be InventoryA.

For example: I have three records mark as Salvage = true (EE00001, EE00002, EE00003). the rest of the TagNo EE are false
so the reports should save like:
EE00001_SalvageA
EE00001_SalvageB
EE00002_SalvageA
EE00002_SalvageB
EE00003_SalvageA
EE00003_SalvageB
the rest of the EE TagNo records would look like
EE00005_InventoryA
EE00006_InventoryA
etc.

But right now, the code doesn't check the record is true or false, it only check the first record, if the first record is true then it assumes all the records are true, if the first record is false then it assumes all the records are false. I don't know how to fix the code to go on by one to check the If condition.

Hope I explained clear.

Thank you for your time.
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:55
Joined
Sep 21, 2011
Messages
14,343
So where does Me.Salvage get set/cleared?

You are referring to a form control and using it's recordsetclone?, which will not change the control?
 

urjudo

Member
Local time
Today, 16:55
Joined
Oct 9, 2020
Messages
67
I have a text box on frmParmEqA for the Salvage, so it will check if the record is true or false.
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:55
Joined
Sep 21, 2011
Messages
14,343
That is no good?, and probably your problem.? You are comparing a static value with dynamic values?
As you are using TempVars already, set a TempVar("Salvage") as you do the TagNo, and test for that instead. ?
 

urjudo

Member
Local time
Today, 16:55
Joined
Oct 9, 2020
Messages
67
you meant instead of If me.Salvage = true, replace with TempVars("Salvage")?
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:55
Joined
Sep 21, 2011
Messages
14,343
you meant instead of If me.Salvage = true, replace with TempVars("Salvage")?
Yes, as that wil be updated on each record? providing you code it that way :)
 

urjudo

Member
Local time
Today, 16:55
Joined
Oct 9, 2020
Messages
67
@Gasman ,
Do I need to change the query? as you can see in my database that I attached on this thread, I used TempVars in the tagno in the query, so I need to do the same?
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:55
Joined
Sep 21, 2011
Messages
14,343
No, just set the TempVar to the Salvage field in the same way that you set the tagno.
 

urjudo

Member
Local time
Today, 16:55
Joined
Oct 9, 2020
Messages
67
@Gasman,
Thanks for your suggested. It works! I have one more question, if the a TagNo has more that one record, I noticed when try to save the next record with the same Tagno overwrite the first one, how do I save it if there is two records under one record.
For example: EE00001 has two records, the first one save as EE00001_SlavageA and the second one should save as EE00001_SalvageA1 instead over write the first one(EE00001_SalvageA) that already saved.

Thank you for your time and patience!
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:55
Joined
Sep 21, 2011
Messages
14,343
The DB you uploaded only has one EE00001 ? in tblMain.?
Should a tag even be duplicated? I thought that was the whole reason for an asset tag, to uniquely identify equipment?
 

urjudo

Member
Local time
Today, 16:55
Joined
Oct 9, 2020
Messages
67
@Gasman
Sorry, in my current Database(not the DB I uploaded), I use the same method as the DB I uploaded for the save report as pdf. I'm trying to save the Employer record(s). An Employee can have more than one employer. so when I save employer records which an employee has two employers, the next employer is replace the first employer, so there should be two employer records save as pdf, it only shows one.
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:55
Joined
Sep 21, 2011
Messages
14,343
@Gasman
Sorry, in my current Database(not the DB I uploaded), I use the same method as the DB I uploaded for the save report as pdf. I'm trying to save the Employer record(s). An Employee can have more than one employer. so when I save employer records which an employee has two employers, the next employer is replace the first employer, so there should be two employer records save as pdf, it only shows one.
Hmm
Perhaps use a DCount() for the relevant field/text and increment accordingly, though for the first that would be 1, so you would have to add some extra logic if you want nothing for the first record and 1 for the second occurrence. Might even be better to have the NoOfJobs as a separate field?

Then again if you used the EmployerID and EmployeeID then there would be no duplicates?
 

urjudo

Member
Local time
Today, 16:55
Joined
Oct 9, 2020
Messages
67
@Gasman,
Sorry to bother you. I did use the DCount but it seems only looking for the first record and not move to the next record. Please let me know if I should post my code. Thanks!
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:55
Joined
Sep 21, 2011
Messages
14,343
DCount() does not look for the first record, DlookUp() does?
All Dcount will do is count the occurrences of the criteria you are working with.?

So if it returns 0, you know that employer/employee record does not exist, so you can save that as you wish.
Then if you use the DCount again, it will return 1 and so you know you need to increment/do whatever you want to indicate a subsequent record for that Employee?

And so on.
 

urjudo

Member
Local time
Today, 16:55
Joined
Oct 9, 2020
Messages
67
@Gasman,
Sorry, not sure how to do this. I used DCount is for if more than one than save both but I guess my code is incorrect so it's only keep saving the first one even if it has two employers
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:55
Joined
Sep 21, 2011
Messages
14,343
From your description you need to adjust the second record before saving if Dcount is not zero?

I would probably have a field for employerID, a field for EmployeeID and make the combination a unique index?

You can upload a DB with enough data to show the problem. I will need the steps to replicate the problem though?

I do not want to have to go and see how it is meant to work. I am not an expert and it would take me some time to get to the bottom of it.

So tell me, what event in what form is having the issue. and what you want it to do.

I will not write it for you, but will try and steer you to a solution.
 

urjudo

Member
Local time
Today, 16:55
Joined
Oct 9, 2020
Messages
67
I do have EmployerCodeID in the form for looking how many employers that the employee has. I will try to get a test DB upload.

Thanks for your time
 

Users who are viewing this thread

Top Bottom