9 Replies - 4665 Views - Last Post: 04 March 2013 - 10:11 PM Rate Topic: -----

#1 aswa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 13-February 13

store data from textboxes/combo boxes in vb6 into MS Access

Posted 13 February 2013 - 08:35 AM

Hey, This is my first post here, and I really need some major help in Visual Basic 6.
I've just started learning this, but my college needs me to do a project within a month.

In one of my forms, the basic Idea is that, when the user enters data into the textboxes/selects an item from a combo box and then clicks a button, i'd like that data to get stored into a table in ms access.

in my form, i have 3 textboxes (text1.text,text2.text,text3.text)and a combo box (combo1) and two buttons "update" and "cancel"

i've managed to work out the cancel button, which on being clicked, clears the data from the textboxes.

my database name is db, and my table name is Log.
the column names in the table are Date, Proj, in_time, Out_time (where proj is what i'm going to get from the combo box)


***NOTE: FOR SOME REASON, ADODC DOESN'T WORK, SO WHATEVER CONNECTIONS I'VE DEFINED IS USING ADODB***

[and i'd also like to know how to define the format of the data being saved into the table. for example i'd like the date format to be in dd/mm/yy]

Thank you! :)

Is This A Good Question/Topic? 0
  • +

Replies To: store data from textboxes/combo boxes in vb6 into MS Access

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: store data from textboxes/combo boxes in vb6 into MS Access

Posted 14 February 2013 - 04:14 PM

Let's start with how you are attempting to use ADO. Don't go back to trying to use the data control, it's a waste of time and you'll get a better grade if you use ADO. What's your code look like? (Please use code tags when posting code, look at the watermark in the box you're typing in to see how.)
Was This Post Helpful? 0
  • +
  • -

#3 aswa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 13-February 13

Re: store data from textboxes/combo boxes in vb6 into MS Access

Posted 17 February 2013 - 07:52 AM

View PostBobRodes, on 14 February 2013 - 04:14 PM, said:

Let's start with how you are attempting to use ADO. Don't go back to trying to use the data control, it's a waste of time and you'll get a better grade if you use ADO. What's your code look like? (Please use code tags when posting code, look at the watermark in the box you're typing in to see how.)


I haven't bothered using adodc for this particular one because it didn't for a login form..so i'll just go on to explain that problem and hopefully if i can get it sorted i can use ado for the other forms too :)
I actually got the login code off the internet, a youtube video..and it worked for him. so I did the same.
but for every line that has the keyword "Adodc" in it, it gets highlighted, with a message box saying- Error 424



here's the code that i tried to use:
private sub command1_click()
 adodc1.recordsource="select * from login where user='" + text1.text + "'"
 adodc1.refresh
 if(adodc1.recordset.eof=false) then
   if(text2.text=adodc1.recordset.fields("pass")) then
     msgbox"login success!"
     me.hide
     form2.show
   else
     msgbox"password incorrect!"
     text1.text=""
     text2.text=""
     text1.setfocus
  End if
 else
  msgbox"invalid username!"
  text1.text=""
  text2.text=""
  text1.setfocus
 End if
End sub



where the table name is login, and the columns for username and password in it are "user" and "pass" respectively.
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: store data from textboxes/combo boxes in vb6 into MS Access

Posted 20 February 2013 - 12:08 AM

ADODC is the ADO Data Control. I wouldn't suggest that you use it. Instead, read up on ADO objects (be careful not to confuse them with ADO.Net) and how to access data with them. Then have a go at making them work, and if you get stuck I'll help you.

If you feel that you just have to use the ADO Data control, then you need to go into the Components menu and set a reference to it, much the same way that you have to go into the References menu and set a reference to ActiveX Data Objects if you want to use ADO. The reason it isn't working is that you aren't telling your application to use it. Something to keep in mind for the future.

This post has been edited by BobRodes: 20 February 2013 - 12:11 AM

Was This Post Helpful? 0
  • +
  • -

#5 josh0709  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 20-February 13

Re: store data from textboxes/combo boxes in vb6 into MS Access

Posted 20 February 2013 - 02:19 PM

This is my first reply made so be patient. You could use the microsoft DAO 3.6 object reference instead. Its a lot simpler to use you just have to save your access database as a 2003 one in save as. so for the code an example in your form load you would enter

Global variables
dim db as Database
dim log as record set

form_load
set db=DBEngine.openDatabase ("dm.mdb)
set Log=db.OpenRecordSet ("Log")
End Sub

command1_click
With log
Log.addnew
Log!Date=text1
Log!In_time=text2
Log!Out_time=text3
.update
end with
'this will add whats in text 1 into the date and whats in text 2 into the In_time etc etc 
'not sure about combo box not really tried it with this method
end sub


Was This Post Helpful? 0
  • +
  • -

#6 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: store data from textboxes/combo boxes in vb6 into MS Access

Posted 24 February 2013 - 05:33 PM

I do not personally recommend that you use DAO over ADO. DAO is even older technology than ADO, and is tied more specifically to certain types of data stores. Josh, you may find that ADO is easier to use than DAO if you spend a little time getting familiar with it.
Was This Post Helpful? 0
  • +
  • -

#7 josh0709  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 20-February 13

Re: store data from textboxes/combo boxes in vb6 into MS Access

Posted 25 February 2013 - 07:55 AM

View PostBobRodes, on 24 February 2013 - 05:33 PM, said:

I do not personally recommend that you use DAO over ADO. DAO is even older technology than ADO, and is tied more specifically to certain types of data stores. Josh, you may find that ADO is easier to use than DAO if you spend a little time getting familiar with it.


I know what you are saying i also use ADO control and know how to use it but just find DAO is easier to use for beginners trying to learn the connection between vb6 and access
Was This Post Helpful? 0
  • +
  • -

#8 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: store data from textboxes/combo boxes in vb6 into MS Access

Posted 03 March 2013 - 09:04 PM

Well, I'm sorry, but I haven't found that in my experience. I've taught quite a few classes in both, and I've actually found ADO easier to teach.
Was This Post Helpful? 0
  • +
  • -

#9 josh0709  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 20-February 13

Re: store data from textboxes/combo boxes in vb6 into MS Access

Posted 04 March 2013 - 03:55 PM

View PostBobRodes, on 03 March 2013 - 09:04 PM, said:

Well, I'm sorry, but I haven't found that in my experience. I've taught quite a few classes in both, and I've actually found ADO easier to teach.


Thats fair enough you have been coding for longer than i have and i am mostly self taught so your probably right just in my experience DAO has always seemed easier.
Was This Post Helpful? 0
  • +
  • -

#10 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: store data from textboxes/combo boxes in vb6 into MS Access

Posted 04 March 2013 - 10:11 PM

I spent from 1996 to 2002 running around the country teaching Microsoft's classes for VB4 through VB6. :) You should give ADO a try. It's more flexible and has a flatter object hierarchy. All you need is a Connection and a Recordset. In DAO you have a Workspace, a Database, a Recordset, and a QueryDef for each query. You also have to set up connections for it to use in whatever database you're working with.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1