none
use datagrid to populate a form for information update RRS feed

  • Question


  • ' QUERY USERS TO FILL DATA TABLE Access.ExecQuery("SELECT * FROM members") ' REPORT & ABORT ON ERRORS If NoErrors(True) = False OrElse Access.RecordCount < 1 Then Exit Sub ' GET FIRST RECORD GetRecord() End Sub Private Sub GetRecord() ' FAIL IF NO RECORDS FOUND OR POSITION IS OUT OF RANGE If Access.DBDT.Rows.Count < 1 OrElse CurrentRecord > Access.DBDT.Rows.Count - 1 Then Exit Sub ' RETRN FIRST USER FOUND Dim r As DataRow = Access.DBDT.Rows(CurrentRecord) ' POPULATE FIELDS txtUserID.Text = r("ID").ToString txtUser.Text = r("username").ToString txtPass.Text = r("password").ToString txtEmail.Text = r("email").ToString txtWebsite.Text = r("website").ToString If r("Active") IsNot Nothing Then cbActive.Checked = r("Active") End Sub

    I have this code that i have learned from multiple sources mainly youtube.

    the code works for what i need but, i want to improve it and get it to use a datagrid to pull the information and populate the relevant text boxes

    So for instance if i select ID 2 i want id twos information on teh second form, but the bellow codes shows all and i need to scroll through the records to find the relevant one

    Private Sub GetUsers()


    Friday, January 19, 2018 12:34 PM

Answers

  • its ok after a bit of trial and error, i was able to edit the code to work for what i needed.

    just took adding a invisible txt box stating the ID number then use that to fill the relevant fields.


    Monday, January 22, 2018 11:50 AM

All replies

  • Hello,

    I'm kind of seeing old ways of doing things with newer ways of doing things in your code e.g. Access.ExecQuery("SELECT * FROM members") almost seems like you are working with VBA while the majority of the code appears to be VB.NET.

    I would suggest looking at the following examples which shows the basics to advance method for working with data including opening another form with a specific record.

    The example below works off a DataGridView (but can be adjusted not too once you have a understanding to what I'm doing in this code sample).

    Full code is here


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, January 19, 2018 12:43 PM
    Moderator
  • is there any way of editing my code to do this
    Friday, January 19, 2018 1:19 PM
  • is there any way of editing my code to do this
    Is this a VB.NET project or not? I can't tell.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, January 19, 2018 1:30 PM
    Moderator
  • This is VB.net, using access as a back end

    it is but this way allows me to hard code parts as they don't want to change i know you can do this multiple way and there is likely a better way but i find this simple

    Monday, January 22, 2018 8:22 AM
  • This is VB.net, using access as a back end

    it is but this way allows me to hard code parts as they don't want to change i know you can do this multiple way and there is likely a better way but i find this simple

    Maybe for you. But I think for others it is like a carpenter who sees somebody nailing something with a screwdriver, who is asked to help and use that same screwdriver to hammer. 

    Success Cor

    Monday, January 22, 2018 8:55 AM
  • This is VB.net, using access as a back end

    it is but this way allows me to hard code parts as they don't want to change i know you can do this multiple way and there is likely a better way but i find this simple

    Well it seems the simply way does not work would you agree that is a correct statement? 

    If you are not willing to try what I suggest then there is nothing more I can do for you.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, January 22, 2018 10:25 AM
    Moderator
  • its ok after a bit of trial and error, i was able to edit the code to work for what i needed.

    just took adding a invisible txt box stating the ID number then use that to fill the relevant fields.


    Monday, January 22, 2018 11:50 AM