Solved

Opening individual record by clicking on Datagrid

Posted on 2003-11-02
7
315 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
Comment Utility
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
Comment Utility
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
Comment Utility
>>  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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:just3082
Comment Utility
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
Comment Utility
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
Comment Utility
How are the controls on Form2 bound to the ADO Control?Which Form is the ADO control on?


0
 

Author Comment

by:just3082
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

762 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

6 Experts available now in Live!

Get 1:1 Help Now