Car fan won't turn on unless AC is on?

I have a 1997 Honda Accord and lately it has been overheating. The fan in the car will not come on unless I run the AC but yesterday I was driving on a cool day with the AC on and it still started to over heat so I pulled over and let it cool down. After that, the check engine light came on.
Please let me know if you know of anything that might be causing this so I can get it fixed. Thank you.
P. S. I have already tried replacing the thermostat and it didn't fix it.

Is your radiator full? Is it leaking? That's the first place i would check if your car is overheating

Honda's are know to be prone to overheating, which is really bad. My 1980 Accord has similar problems so we wired one of the two fans to run all the time.

I would also do a compression test to check if the head and head gasket are still good, being a 97 I would be very concerned if you still have the original head gasket in the engine.

It sounds like you need a new cooling fan temperature switch.