Connecting Access and VB 6 application

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Tshimega

Thread Starter
Joined
Aug 18, 2004
Messages
13
Hi,

I have a form in VB 6 called frmEMPLOYEE with 3 textboxes namely: First_Name, Last_Name and Employee_Id . I also have a table in access called tblEMPLOYEE. How to I create a button to take whatever that I have on the text boxes and puts in into the database.

I have tried:


Private Sub Command1_Click()

Dim Rs As Recordset

'Set Rs = CurrentDb.OpenRecordset("tblEmployee", dbOpenTable)

Rs.AddNew

Rs("Employee_Id").Value = Text3
Rs("First_Name").Value = Text1
Rs("Last_Name").Value = Text2

Rs.Update
End Sub

But this doen't help. Again how do I link the application with the database. I am using access 2000 and VB 6

Thanks
 
Joined
Jul 26, 2004
Messages
11
You don't need a command button to update your table. Make sure the record source for your form is your table and for each text box, the control source is the field name (coulmn name) for each.
 
Joined
Jul 26, 2004
Messages
11
You don't need a command button to update your table. Make sure the record source for your form is your table and for each text box, the control source is the field name (coulmn name) for each.
 

Tshimega

Thread Starter
Joined
Aug 18, 2004
Messages
13
Thanks...another problem

I have created a table in access and on one of the fields in Employer table, I have stored a picture in the column "IMAGE" as an OLE object. Now I have created a form in VB 6 and I have linked all other fields successfull and they do appear on the form. On the same form I want to also to display the picture relating to the same employee that is in the database in the VB 6 form. When I try linking the Image box to the recordsourde, say "adoEmployee" and then I choose the datafield as "Image", running the form displays a message "Unable to bind field or DataMember: IMAGE"....please help....

Beginner
 
Joined
Jul 26, 2004
Messages
11
Open a data access page in Design view.

In the toolbox, click the Image tool (drag your mouse over it so you'd know which one it's. It looks like a couple of hills with the sun on top :)).


Click Field List (it looks like a document) on the toolbar to display the field list.


From the field list, drag the field that contains a path to an image to the data access page (I think you named this column Image, so just drag that to your form where you want the pic to be displayed). Place the upper-left corner of the icon where you want the upper-left corner of the image to be, and release the mouse button.

That's it....
 
Joined
Oct 12, 2003
Messages
3,015
The problem with the code you post is as follows:

Code:
Rs("First_Name").Value = Text1
should be ...

Code:
Rs.Fields("First_Name").Value = Text1.Text
Note that I dislike depending on default properties. For one thing, VB.Net doesn't support them so at some point you're going to have to change this code to comply with that if you plan on it being around that long.

Alternatively, you can also reference the database columns without the invoking the .Fields collection like this

Code:
Rs!First_Name = Text1.Text
Data binding is a good idea and it has its place but it's not always the answer. It surely makes it easier to update existing data by just changing it on the screen and letting the database provider do the work for you. Like I said though, it's not the answer for everything. (In my humble opinion.)
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top