Where in the Old or New Testament does it forbid or warn a married man not to be in the company of other women?

When you speak of a married man being in the company of other women, I am assuming you mean romantic interest is involved.

The Bible is very explicit — extra marital interest is totally unacceptable to God. A small selection of passages from the Old and New Testament addressing these issues:

Proverbs 2:16-19:
So you will be delivered from the forbidden woman, from the adulteress with her smooth words, (17) who forsakes the companion of her youth and forgets the covenant of her God; (18) for her house sinks down to death, and her paths to the departed; (19) none who go to her come back, nor do they regain the paths of life.

Proverbs 5:3-8:
For the lips of a forbidden woman drip honey, and her speech is smoother than oil, (4) but in the end she is bitter as wormwood, sharp as a two-edged sword. (5) Her feet go down to death; her steps follow the path to Sheol; (6) she does not ponder the path of life; her ways wander, and she does not know it. (7) And now, O sons, listen to me, and do not depart from the words of my mouth. (8) Keep your way far from her, and do not go near the door of her house,

Proverbs 5:15-23:
Drink water from your own cistern, flowing water fromyour own well. (16) Should your springs be scattered abroad, streams of water in the streets? (17) Let them be for yourself alone, and not for strangers with you. (18) Let your fountain be blessed, and rejoice in the wife of your youth, (19) a lovely deer, a graceful doe. Let her breasts fill you at all times with delight; be intoxicated always in her love. (20) Why should you be intoxicated, my son, with a forbidden woman and embrace the bosom of an adulteress? (21) For a man’s ways are before the eyes of the LORD, and he ponders all his paths. (22) The iniquities of the wicked ensnare him, and he is held fast in the cords of his sin. (23) He dies for lack of discipline, and because of his great folly he is led astray.

Proverbs 6:23-29:
For the commandment is a lamp and the teaching a light, and the reproofs of discipline are the way of life, (24) to preserve you from the evil woman, from the smooth tongue of the adulteress. (25) Do not desire her beauty in your heart, and do not let her capture you with her eyelashes; (26) for the price of a prostitute is only a loaf of bread, but a married woman hunts down a precious life. (27) Can a man carry fire next to his chest and his clothes not be burned? (28) Or can one walk on hot coals and his feet not be scorched? (29) So is he who goes in to his neighbor’s wife; none who touches her will go unpunished.

Proverbs 7:5-27:
to keep you from the forbidden woman, from the adulteress with her smooth words. (6) For at the window of my house I have looked out through my lattice, (7) and I have seen among the simple, I have perceived among the youths, a young man lacking sense, (8) passing along the street near her corner, taking the road to her house (9) in the twilight, in the evening, at the time of night and darkness. (10) And behold, the woman meets him, dressed as a prostitute, wily of heart. (11) She is loud and wayward; her feet do not stay at home; (12) now in the street, now in the market, and at every corner she lies in wait. (13) She seizes him and kisses him, and with bold face she says to him, (14) “I had to offer sacrifices, and today I have paid my vows; (15) so now I have come out to meet you, to seek you eagerly, and I have found you. (16) I have spread my couch with coverings, colored linens from Egyptian linen; (17) I have perfumed my bed with myrrh, aloes, and cinnamon. (18) Come, let us take our fill of love till morning; let us delight ourselves with love. (19) For my husband is not at home; he has gone on a long journey; (20) he took a bag of money with him; at full moon he will come home.” (21) With much seductive speech she persuades him; with her smooth talk she compels him. (22) All at once he follows her, as an ox goes to the slaughter, or as a stag is caught fast (23) till an arrow pierces its liver; as a bird rushes into a snare; he does not know that it will cost him his life. (24) And now, O sons, listen to me, and be attentive to the words of my mouth. (25) Let not your heart turn aside to her ways; do not stray into her paths, (26) for many a victim has she laid low, and all her slain are a mighty throng. (27) Her house is the way to Sheol, going down to the chambers of death.

Proverbs 22:14:
The mouth of forbidden women is a deep pit; he with whom the LORD is angry will fall into it.

Ecclesiastes 7:26:
And I find something more bitter than death: the woman whose heart is snares and nets, and whose hands are fetters. He who pleases God escapes her, but the sinner is taken by her.

1 Corinthians 6:9:
Or do you not know that the unrighteous will not inherit the kingdom of God? Do not be deceived: neither the sexually immoral, nor idolaters, nor adulterers, nor men who practice homosexuality,

Hebrews 13:4:Let marriage be held in honor among all, and let the marriage bed be undefiled, for God will judge the sexually immoral and adulterous.