Hi there.
Using VB5

I am a real novice to VB but slowly getting the grasp of thing but at the moment writing things out long hand (thinking there must be short cuts)

Like filling a VB form with MSACCESS data I am detailing every field e.g.

txtCompGST.Text = tldt.Rows(rowpos)("CompGST").ToString()
            txtCompName.Text = tldt.Rows(rowpos)("CompName").ToString()
            txtCompAdmin.Text = tldt.Rows(rowpos)("CompAdmin").ToString()
            txtCompUnit.Text = tldt.Rows(rowpos)("CompUnit").ToString()
            txtCompHouse.Text = tldt.Rows(rowpos)("CompHouse").ToString()
            txtCompStreet.Text = tldt.Rows(rowpos)("CompStreet").ToString()
            txtCompSuburb.Text = tldt.Rows(rowpos)("CompSuburb").ToString()
            txtCompCity.Text = tldt.Rows(rowpos)("CompCity").ToString()
            txtCompPostCode.Text = tldt.Rows(rowpos)("CompPostCode").ToString()

and for updating e.g.

tldt.Rows(rowpos)("CompGST") = txtCompGST.Text
        tldt.Rows(rowpos)("CompName") = txtCompName.Text
        tldt.Rows(rowpos)("CompAdmin") = txtCompAdmin.Text
        tldt.Rows(rowpos)("CompUnit") = txtCompUnit.Text
        tldt.Rows(rowpos)("CompHouse") = txtCompHouse.Text
        tldt.Rows(rowpos)("CompStreet") = txtCompStreet.Text
        tldt.Rows(rowpos)("CompSuburb") = txtCompSuburb.Text
        tldt.Rows(rowpos)("CompCity") = txtCompCity.Text
        tldt.Rows(rowpos)("CompPostCode") = txtCompPostCode.Text
        tldt.Rows(rowpos)("CompPhone") = txtCompPhone.Text

and new information e.g.

Dim drNewRow As DataRow = tldt.NewRow()
        drNewRow("CompGST") = txtCompGST.Text
        drNewRow("CompName") = txtCompName.Text
        drNewRow("CompAdmin") = txtCompAdmin.Text
        drNewRow("CompUnit") = txtCompUnit.Text
        drNewRow("CompHouse") = txtCompHouse.Text
        drNewRow("CompStreet") = txtCompStreet.Text
        drNewRow("CompSuburb") = txtCompSuburb.Text
        drNewRow("CompCity") = txtCompCity.Text
        drNewRow("CompPostCode") = txtCompPostCode.Text

I can see this is going to be very time comsuming for all the forms I will need to create. I have searched manuels and web for specifics but am getting a little lost.

Can someone please point me in the right direction to simplify this task


Many thanks
Craig

Recommended Answers

All 4 Replies

Use ADO or DAO control

With any of these control you can easily connect your db (to the control) and then your other controls (e.g. textbox) to the ADO or DAO which ever the case may be. then you can add, update or delete respectively with the code;

dataobject.recordset.addnew
dataobject.recordset.update
dataobject.recordset.delete

where dataobject is the name given to the ADO or DAO control.

Thank you for your reply

Just to confirm:
Will this code autofill the fields in my form when I open it or do I still need to use the code in my previous post to bring all the information over from MSACCESS?

Again thank you for the pointer

Again many thanks

That was very helpful

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.