Solved

Opening individual record by clicking on Datagrid

Posted on 2003-11-02
7
319 Views
Last Modified: 2013-12-25
Using VS6 SP5, Ado , Win2K and Access 2K.

Have a datagrid returning records, wanted to double click on individual record
and it open in its own form for editing purposes. Vinnyd179 provided the code below which works great, however when I change a control's value and
close with Adodc1.Recordset.Update, it doesn't update the record. I assume
the code below only populates the controls and doesnot allow editing...
Can anyone explain to me how to make this form update the current record that is being displayed,( I assume that the record isn't actually opened and that the values that have changed actually need to be inserted back into the Access DB, But I just don't know how to open that exact individual record and append the updates.....

use the double click event of the grid:

' assumes rs is a public recordset

Private Sub DataGrid1_DblClick()
Load Form2
' clear boxes
Form2.Text1 = ""
Form2.Text2 = ""
Form2.Text3 = ""
' populate Textboxes from rs recordset
With rs
    Form2.Text1 = .Fields("Field1").Value
    Form2.Text2 = .Fields("Field2").Value
    Form2.Text3 = .Fields("Field3").Value
End With

Form2.Show

End Sub


Just3082
0
Comment
Question by:just3082
  • 4
  • 3
7 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9667336
Have you tried using the adodc instead of a recordset in the above?

' populate Textboxes
With Adodc1
    Form2.Text1 = .RecordSet.Fields("Field1").Value
    Form2.Text2 = .RecordSet.Fields("Field2").Value
    Form2.Text3 = .RecordSet.Fields("Field3").Value
End With
0
 

Author Comment

by:just3082
ID: 9667448
Yes, This is what I have: However  form2(Assigned_Tickets) opens
and displays the info fine, I can't change any of the data. I can, but it doesn't
send it back to the DB. I've got the controls on the form bound to Adodc1, So
I can't figure out why it isn't working.... Look below the first code for the code in the second form.

Private Sub DataGrid1_DblClick()
Load Assigned_Tickets
Assigned_Tickets.Text1 = Adodc1.Recordset.Fields("Issue").Value & ""
Assigned_Tickets.Text2 = Adodc1.Recordset.Fields("Resolution").Value & ""
Assigned_Tickets.Text3 = Adodc1.Recordset.Fields("Requestor").Value & ""
Assigned_Tickets.Text4 = Adodc1.Recordset.Fields("Time").Value & ""
Assigned_Tickets.Text5 = Adodc1.Recordset.Fields("TicketID").Value & ""
Assigned_Tickets.Text6 = Adodc1.Recordset.Fields("CallTakenBy").Value & ""
Assigned_Tickets.Text7 = Adodc1.Recordset.Fields("Date").Value & ""
Assigned_Tickets.Text8 = Adodc1.Recordset.Fields("ResponseToRequestor").Value & ""
Assigned_Tickets.Text9 = Adodc1.Recordset.Fields("NotesToTech").Value & ""
Assigned_Tickets.Text10 = Adodc1.Recordset.Fields("Extension").Value & ""
Assigned_Tickets.Text11 = Adodc1.Recordset.Fields("Location").Value & ""
Assigned_Tickets.Combo1 = Adodc1.Recordset.Fields("Status").Value & ""
Assigned_Tickets.Combo2 = Adodc1.Recordset.Fields("AssignedTo").Value & ""
Assigned_Tickets.Combo3 = Adodc1.Recordset.Fields("Category").Value & ""
Assigned_Tickets.Combo4 = Adodc1.Recordset.Fields("Escalate").Value & ""
Assigned_Tickets.Combo5 = Adodc1.Recordset.Fields("Department").Value & ""
Assigned_Tickets.Text12 = Adodc1.Recordset.Fields("ComputerName").Value & ""
Assigned_Tickets.Text14 = Adodc1.Recordset.Fields("UserName").Value & ""
Assigned_Tickets.Show
Unload JMHTickets
End Sub


Private Sub Update_Click()
Adodc1.Recordset.Update
Unload Me
JMHTickets.Show
End Sub

Just3082
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 125 total points
ID: 9667487
>>  I've got the controls on the form bound to Adodc1

If they are bound,then wouldn't they be populated without the need for setting the Text to the record values like this:

Assigned_Tickets.Text1 = Adodc1.Recordset.Fields("Issue").Value & ""

Are you binding the Textboxes on Form2 to the ado control on form1?




0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:just3082
ID: 9667618
Ok, Everything is working fine now. Apparently all I needed to know to begin with was how to change the record selection in the grid to Row.
This is why before when I click on it, it would open form2, but display
the first record in the DB instead of the record I thought I was clicking on, When in actuality I was clicking on a field, because I didn't have the Row selection enabled. Yes, I feel pretty dumb.....

Thanks Vinnyd179 ....

Just3082
0
 

Author Comment

by:just3082
ID: 9671232
No, I was wrong. When I double click on a record it opens my form2, however it displays
the first record in the set instead of the actual record I double clicked on in the datagrid from form1...

Just3082
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9674999
How are the controls on Form2 bound to the ADO Control?Which Form is the ADO control on?


0
 

Author Comment

by:just3082
ID: 9680888
The first form is a simple datagrid with adodc1 to my Ticket database
the second form is full of controls, ADODC1 also to my tickets database, However I have
the adodc1 control disabled on form2 and hidden. I only want the record I clicked on to
be displayed. To answer your question: the controls on form2 are bound through VS6.
I've selected each control and chose adodc1 and the corresponding value in the datafield.

Just3082
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need VBS version of Excel date conversion 4 70
Problem to skip loop 6 56
VB error "Type mismatch" 2 53
Help me. 3 54
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now