Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using the same adodc connection for two separate forms
Message
General information
Forum:
Visual Basic
Category:
Database DAO/RDO/ODBC/ADO
Miscellaneous
Thread ID:
00614693
Message ID:
00615983
Views:
13
Hi Eric,
I have the code for form1 and form2 exactly as you wrote. On form1 however I have a text box that displays a field from table2 instead of table1 and when using the command button to show form2 I have code that checks to see if there is anything in that text box and if there is then it will just show form2 otherwise I want it to add a new record so that data can be entered. Basically I want the user to be able to see the second form if they need to change information in any of the fields or if they need to enter a new record that corresponds to the one in the first table. I know I must be going about this the wrong way. What code do I place on the command button (of the first form that shows the second form) to add a new record to the second table if there is none corresponding already and if there is one then to just show the form so that it can be updated? Then what code do I use on the command save button on the second form to make it work for either choice? Here is what I have tried but I know it's wrong:

If txtField2ndTbl.Text = "" Then
adodc1.Recordset.addnew
form2.Show
Else
form2.Show
End If

Then when the second form is opened on the command save click event I have this code:

Private Sub cmdSave_Click()
adodc1.Recordset.Update
End Sub

It works for adding a new record but when I click save after changing a field in form2 it gives an error message:

Run-time error
Insufficient key column information for updating or refreshing.

I changed the EOF action for the adodc of form1 to adDoAddNew as well.
Also when I do get the new record added and close form2 (form1 is behind still) form1 shows all the fields as blank and if I close it and open it again then it will show the record but does that mean it's trying to insert a new record in table1 as well? I only want the record to be inserted into table2.
How do I determine if form2 is Data Bound?
Thanks again!!
Max
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform