Adding new records to a VB 6 DB Grid Control with no data to start with


I have been struggling to add a new record to a DB grid in VB 6. I did set the AllowAddNew property to true, here is my code:

Private Sub BindDetailFields()
    Dim sSQLDetail As String
    sSQLDetail = " SELECT b.PONumber, b.TiresOrEquipment, b.UnitNumber, b.ItemNbr, b.ItemDesc, "
    sSQLDetail = sSQLDetail & " b.QuantityOrdered, b.OrigUnitCost, b.OrigExtendedCost "
    sSQLDetail = sSQLDetail & " FROM " & strCustomDB & "..PORDetail b "
    sSQLDetail = sSQLDetail & " WHERE PONumber = '" & txtPONumber.Text & "'"
    rsPODetail.Open sSQLDetail, cnGPCustom, adOpenDynamic, adLockOptimistic
    If rsPODetail.EOF = False And rsPODetail.RecordCount > 0 Then
    End If
    If blnAddNew = True Then
        With rsPODetail
            .Fields("PONumber") = txtPONumber.Text
            .Fields("TiresOrEquipment") = " "
            .Fields("UnitNumber") = " "
            .Fields("ItemNbr") = " "
            .Fields("ItemDesc") = " "
        End With
    End If
    DataGridPODetail.AllowAddNew = True
    Set DataGridPODetail.DataSource = rsPODetail
End Sub

The Boolean variable blnAddNew is a private form level variable that is set to True when a user clicks on the Add New button on the form. The txtPONumber.Text is dynamically generated with a formula and hasTo start with, the recordset does not have any records.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi csrirram,
             I believe I have a good understanding of your question now.  Forgive me if I am wrong, but it sounds like your     rsPoDetail.Requery   should be      rsPoDetail.Refresh.  Let me know if that helps please.
csriram_leafAuthor Commented:
No, that was not it. There is no Refresh property available for the ADODB recordset through Intellisense. Maybe it is a hidden property. But my underlying problem was that the data grid control would not bind to a dynamic cursor and kept giving me errors, there were no errors with rsPODetail.Requery statement.

When I changed the statement

 rsPODetail.Open sSQLDetail, cnGPCustom, adOpenDynamic, adLockOptimistic


 rsPODetail.Open sSQLDetail, cnGPCustom, adOpenStatic, adLockOptimistic

and then added the new record to the recordset and bound the data grid control, the data grid control was able to display the new record without any errors

Now, I just need to figure out a way to retrieve the column index when I click on any cell in the grid. Let me know if you can help me with that.

Thanks for your time.

BarshamDevelopment Team LeadCommented:
u can use DBGrid.Col Property but in first click it does not work ,must have 2 click maybe this is a bug :-/

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.