This is hard to answer generally, any answer might be on the verge of oversimplification.
Very generally, you can assume that Language, specifically everyday Language, is going to find the easy way out, the easiest way to express a matter. If it doesn't, it might be going to end up sophisticated, of elevated style, or even highbrow (you might, in cases, aim for the first and second, but maybe not for the third).
The easiest way out for the native speaker is using a preposition: In most cases the preposition will clearly rule a specific case, and can be used without much thinking. You can also expect to be understood better, because the preposition adds further redundancy to your sentence other than the case only. Most people will thus, in everyday speech, generally go for the preposition - It is just simpler to use.
Written language like newspaper articles and books have other preferences, though. Style, brevity and being to the point might be more important. In a newspaper article, you might preferably use sich einer Gruppe anschliessen rather than sich an eine Gruppe anschliessen. But still, there's a limit - Your second example will very probably not be used by anyone without a preposition - be it spoken language or in writing, no one will ever say or write ich habe den Text der Tafel angeschrieben.
Also note there might be standing idioms that either prefer the one or the other (sich einer Gruppe anschließen might be considered such an idiom).
For a language learner and if unsure, the rule is maybe clear: Go for the prepositional object construct, it is simpler to learn and use - It's just easier to get it wrong without. Once you manage to use the finer points of the language, you will start to develop a feel when you can use dative objects.