Click to See Complete Forum and Search --> : if else


remcoploeg
August 15th, 2001, 08:40 AM
I have a problem with vb6. I need a statement that create a new record with a variabele. For example: In form1 if got a id. I go to form2 to view a report about that id, but there isn't any report, so I need a new one. But sometimes the report exist and then I want to edit it. Edit works now. But I need a statement that vb6 can see If the report exist, if it not, then create a new one, with that ID. Can anybody help me??


thnks

Remco Ploeg
ploegr@promar-agencies.nl

CodeBlue
August 15th, 2001, 10:27 PM
What are you using to create the report? Are you creating it directly onto Form2 by using print statements etc? If so, you could check to see if Form2 exists. The report must be an "object" of some kind. Do you maintain a variable that holds an object pointer to the report? If so, you could see if it already exists...

If Report1 is Null
'... create the report
Else
'... edit the report
Endif

remcoploeg
August 16th, 2001, 01:47 AM
Yes i have a variable. On form1 I have an object_id. I go to form2 a there I go to another table to see more about the object_id. But sometimes, the object_id excist in form1(other table then form2) but when I go to form2, I want a sql statement that check if it is already in the table of form2. If not, I need adodc1.recordset.addnew. If he excist I need a select statement.
Example:
Form1: object_id name city
1 Test Rotterdam
This is in table bas_tb_object
Now I got to form2 with a command button:
form2: object_id paid
1 yes
This is in table bas_tb_paid
But when I create a new object in form1(bas_tb_object), it is not in form2(bas_tb_paid), so I need a sql statement to check that, if it not excist Addnew, else select .....

This is just a example,

Thanks

Remco Ploeg
ploegr@promar-agencies.nl

Sephozzy
August 16th, 2001, 04:20 AM
I don't know how your tables are designed but I think that if you have a solid design there could never be a bas_tb_paid object for a bas_tb_object that doesn't exist. So if you make a new object in form1 you can be sure that there is no corresponding paid_object. After all it would be silly if you have the payment status for an object that doesn't exist.
So now that we create a new object we can also create the corresponding paid_object with Addnew and set it to a default value (not paid?). All you have to do when you switch to form2 is refresh the table and you should have a list of all paid_objects.

I just realized that you probably have a 1-on-1 relation between the two tables. Why not just make 1 table with everything already in there:
object_id name city paid
1 Test Rotterdam true
2 Remco Amsterdam false
3 Sephozzy Antwerpen false
...
That way you are always certain that the paid_object exists if the object exists.

Just some thoughts

remcoploeg
August 16th, 2001, 04:58 AM
With the paid is just an example. Ok this:
table(relations), CompanyID Name
table(reports), VisId, CompanyID, Date visit, Impression

I go to the relations table(form1) there I choose one relation en push a button and go to form2, on form2 you have an impression about the visit. But not all the relations are visited. So when I choose a relation without a visit yet, and somebody visited the company, he want to make a report. So the report does not excist. So I want to check if there is already a report and if there's not, create one, If he exist(because they already visited the company last year) show the report.



Remco Ploeg
ploegr@promar-agencies.nl