New User : VB6 Project : Database Problem
Hi
I am a newbie to VB6.. Ive read many helps and all and i am trying to make a Access DB driven Project.. Here is a simple code for adding some form info to the database..
VB Code:
Private Sub cmdadduser_Click()
'Checking for no field to be empty
If txtid.Text = vbNullString Or txtpassword.Text = vbNullString Or _
txtname.Text = vbNullString Or txtaddress.Text = vbNullString _
Or txtemail.Text = vbNullString Or txtphone.Text = vbNullString Then
MsgBox "All Fields Must Contain Data", vbCritical, "Error"
Else
'Adding the Record
rs.AddNew
rs("ebay_id") = txtid.Text
rs("password") = txtpassword.Text
rs("name") = txtname.Text
rs("address") = txtaddress.Text
rs("email") = txtemail.Text
rs("phone") = txtphone.Text
rs.Update
MsgBox "You for Registering Please Login Now", vbOKOnly, "Successful"
Unload frmnewuser
frmwelcome.Show
End If
End Sub
Private Sub cmdreset_Click()
' Reseting All textboxes
txtid.Text = ""
txtname.Text = ""
txtpassword.Text = ""
txtaddress.Text = ""
txtemail.Text = ""
txtphone.Text = ""
txtid.SetFocus
End Sub
Private Sub cmdreturn_Click()
Unload Me
frmwelcome.Show
End Sub
Private Sub Form_Load()
Dim db As Database
Dim rs As Recordset
Dim ws As Workspace
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(App.Path & "\db.mdb")
Set rs = db.OpenRecordset("user_info", dbOpenTable)
End Sub
According to me everything is fine.. But when i run the program.. I get the following error
424 : Object required
on line
Please tell me what Am i doing wrong and what is to be corrected?? Maybe my connection is not right??
Re: New User : VB6 Project : Database Problem
Your DB elements are only going to be active in Form_Load.
You need to declare tem at the top of the form, before any procedures are called.
VB Code:
Option Explicit
Private db As Database
Private rs As Recordset
Private ws As Workspace
Private Sub Form_Load()
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(App.Path & "\db.mdb")
Set rs = db.OpenRecordset("user_info", dbOpenTable)
End Sub
'place the rest of your subs down here
I use ADODB.
With it you have to use the NEW command like this.
VB Code:
Set rs = New ADODB.Recordset
Re: New User : VB6 Project : Database Problem
I am new to this..
it has started working.. thanks
so do i use ADOBD??? y?? tell me what will the commands look like ?
what am i using right now then??
also can i put all these in a BAS file
Dim db As Database
Dim rs As Recordset
Dim ws As Workspace
so i dont need to do it everytime in every form?? i have created a BAS file but dont know how to use it in a form or all form
Please help in all these queries...
Re: New User : VB6 Project : Database Problem
Quote:
Originally Posted by khandu
I am new to this..
it has started working.. thanks
so do i use ADOBD??? y?? tell me what will the commands look like ?
what am i using right now then??
also can i put all these in a BAS file
Dim db As Database
Dim rs As Recordset
Dim ws As Workspace
so i dont need to do it everytime in every form?? i have created a BAS file but dont know how to use it in a form or all form
Please help in all these queries...
The DAO that you are using is old technology but there's nothing really wrong with it. To make your variables available everywhere do the following in your code module.
VB Code:
Public db As Database
Public rs As Recordset
Public ws As Workspace
Re: New User : VB6 Project : Database Problem
Here's a good tutorial by Si that might help you.
http://www.vbforums.com/showthread.php?t=337051
Re: New User : VB6 Project : Database Problem
Oh, BTW, Welcome to the Forum!
Re: New User : VB6 Project : Database Problem
Thanks for the help.. module also working as a charm now..
Now..
I want to make such a drop down list which will contain fields from a table
when a user selects the particular item from list.. some text boxes get autofilled by the corresponding fields..
Now i have used the Data control to attach the corresponding textboxes and list to the data fields..
But data is not showing there.. How do i do this and how to populate the corresponding data to the remaining text boxes..
hope its clear from my side :)
Re: New User : VB6 Project : Database Problem
Before you bind them, are there fields with nulls in your table? If yes, then don't bind them, manually populate them.
To handle nulls for strings (eg. for display in textboxes)
rs.Fields(fieldname or index).Value & "" 'this creates a zero length string from null
Re: New User : VB6 Project : Database Problem
none are nul..
How do i fill the combo dropdown with the field i have linked it too..
and then how do i fill the rest of textboxes with corresponding values to the chosen dropdown..
Re: New User : VB6 Project : Database Problem
Once you have the data control (or microsoft ADO data control 6) setup then you can bind the textboxes by setting their datasource and datafield properties... data bound combo and list controls are in microsoft databound list controls 6 (for DAO) and microsoft datalist controls 6 (ADO/DAO and optimized for ADO)
Just make sure you don't confuse ADO with DAO. Each has its own set of databound controls and data sources.