The accusative case is used for the direct object of a verb. In "Bob eats lunch," "lunch" is the direct object.
The dative case is used to denote indirect objects, which are objects that indicate "to whom", or "to what" an action is done. So in the sentence, "I am writing a letter to you", "(a) letter" is the direct object of the verb, while '(to) you' is the indirect object.
So, direct objects go in the accusative case, and indirect objects go in the dative case.