Welcome to the forum. You've found the right place to discuss VFP and get answers to your questions.
Olaf has given you some useful information. But he also points out that we need to know more about your overall situation, and in particular whether you are using third-party software.
For now, I will assume that you are developing all the software yourself, and that you have full control over your programming environment and also your database.
In that case, the short answer to your question (how to "generate the invoice automatically as soon as a record inset into one of table") is to set up an INSERT trigger on the table in question. This is done at the database level. In other words, you write code in the SQL Server language (T-SQL) and store it in the database. That code will have access to all the data in the record that you are inserting, as well as data from the other tables, and you will use this to generate the invoice. The invoice will be held as another record in a table somewhere in the database. Your VFP program will then access that data to physically print the invoice, generate a PDF, or whatever.
So, that's the short answer. But I wonder if that it is really what you want to do. The problem with a trigger is that it will
always fire when the relevant action takes place (in this case, an INSERT), regardless of the reason for the action. So if you are inserting records for some other reason, your application won't be behaving as designed.
Another reason not to use triggers (in this case) is that it will mean spreading your code over two different platforms: VFP and SQL Server, with all that that implies for debugging and maintenance. And if you ever move the back-end database to a different platform, you might have to rewrite the trigger code, because of variations in SQL dialects.
For those reasons, a better approach would be to write the invoice-generating code in VFP. Make it into a self-contained function (or procedure or method). And call that function immediately after whatever code you are using to insert the record. That way you will have complete control over the timing of the invoice generation, and all your code will be under the same roof.
If you want to know how to write code to generate an invoice in VFP ... well, that's a completely different question.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads