It's a bit hard to follow the logic, and I didn't fully study the code. But I see a few things that might be an issue.
myFile: You open this file every time menu 1 is entered, and you read from it after an escape is typed. But you never close the file, nor do you ever write to it.
myFile2: You open this file every time menu 3 is entered, then you have a comment to read it until there's nothing left, but you don't actually read anything. Then if escape is typed, you call read_file2() to copy everything from the file to the LCD. Then you delay. Finally, you remove the file, but you haven't closed the file. I don't know how happy the library is going to be attempting to delete an open file out from under itself. Then, when you've sent a message, you once again open the file, write the string, and finally close the file.
With myFile, you are constantly reopening the file, but never writing to it, nor closing it.
With myFile2, you are properly closing the file after writing it, but you aren't closing it after reading it and before deleting it.
In addition, your code flow is quite convoluted and hard to follow. It looks like you started out by trying a bunch of different things, adding little bits here and there to add new functionality. It's very easy to get lost working that way.
My recommendation is to use this code as a good learning experience. You now have a pretty good idea of what you want to do. Take the time to organize your thoughts, and write down a concise description of what you want it to do. Don't worry about HOW to do it, just clearly state WHAT it should do, For example: "display the last sent message on the screen" not "read an SD file and copy it to the display."
If you do that, and think about what you want it to do, you should be able to come up with a clearer organization. You will also be able to determine the best way to do things. For example, your previously stated goals of saving all of the messages to an SD card file, and also saving only the last message to the SD card file are mutually exclusive.
Writing to an SD card is good for long term storage (logging ALL messages) it is not good for short term storage (remembering the last written message so it can be displayed.) A variable in RAM is much better for the latter. Trying to make the file do both things is an exercise in frustration. You are currently using kbdata to temporarily hold the message that is being created. That's a good use of a variable. You then write it out to the file, and reset kbdata in preparation for the next message. At that point, it would make sense to copy the contents of kbdata to a new variable (something like lastSentMessage) before you reset kbdata. That way, when it comes time to display the last sent message, you can just write the lastSentMessage string to the LCD without having to call read_file2 and extract it from the SD card. You would already have it in memory. This would get rid of a lot of open/close calls, and eliminate the need to keep deleting the SD card file.
Given what you've said in the past, it seems a more logical way to handle the data would be:
- Open a single SD file in setup()
- every time you send or receive a message, write the message to the SD card with a prefix like "S:" for a sent message, and "R:" for a received message. Do this with a function that takes the prefix and the message as arguments.
- When you create a message, save a copy of it in a variable for easy display. Overwrite that saved value with the new value the next time you create a new message.
- When you receive a message, save a copy of it in another variable for easy display. Overwrite that one as well when a new message comes in.
- When it's time to display a message, just use the last value from one of those saved variables, rather than go to the SD card.
- Strive to make it more modular. Make functions for each menu mode. Then, when you decode a menu key press, cal the function for that menu item. It will make your loop() function much easier to read.
The second time you are typing a very similar sequence of code, consider putting it in a function. The third time you are typing the same sequence of code, it definitely should be in a function.