Results 1 to 10 of 10

Thread: New User : VB6 Project : Database Problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Unhappy 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:
    1. Private Sub cmdadduser_Click()
    2.  
    3. 'Checking for no field to be empty
    4.  
    5. If txtid.Text = vbNullString Or txtpassword.Text = vbNullString Or _
    6. txtname.Text = vbNullString Or txtaddress.Text = vbNullString _
    7. Or txtemail.Text = vbNullString Or txtphone.Text = vbNullString Then
    8.  
    9. MsgBox "All Fields Must Contain Data", vbCritical, "Error"
    10.  
    11.  
    12.  
    13. Else
    14.  
    15.  
    16. 'Adding the Record
    17.  
    18.   rs.AddNew
    19.   rs("ebay_id") = txtid.Text
    20.   rs("password") = txtpassword.Text
    21.   rs("name") = txtname.Text
    22.   rs("address") = txtaddress.Text
    23.   rs("email") = txtemail.Text
    24.   rs("phone") = txtphone.Text
    25.   rs.Update
    26.  
    27. MsgBox "You for Registering Please Login Now", vbOKOnly, "Successful"
    28.  
    29.  
    30. Unload frmnewuser
    31. frmwelcome.Show
    32. End If
    33.  
    34. End Sub
    35.  
    36. Private Sub cmdreset_Click()
    37.  
    38. ' Reseting All textboxes
    39.  
    40. txtid.Text = ""
    41. txtname.Text = ""
    42. txtpassword.Text = ""
    43. txtaddress.Text = ""
    44. txtemail.Text = ""
    45. txtphone.Text = ""
    46. txtid.SetFocus
    47.  
    48. End Sub
    49.  
    50. Private Sub cmdreturn_Click()
    51.  
    52. Unload Me
    53. frmwelcome.Show
    54.  
    55. End Sub
    56.  
    57. Private Sub Form_Load()
    58.  
    59. Dim db As Database
    60. Dim rs As Recordset
    61. Dim ws As Workspace
    62.  
    63. Set ws = DBEngine.Workspaces(0)
    64. Set db = ws.OpenDatabase(App.Path & "\db.mdb")
    65. Set rs = db.OpenRecordset("user_info", dbOpenTable)
    66.  
    67. End Sub

    According to me everything is fine.. But when i run the program.. I get the following error

    424 : Object required

    on line

    VB Code:
    1. rs.addnew

    Please tell me what Am i doing wrong and what is to be corrected?? Maybe my connection is not right??
    Last edited by khandu; Dec 17th, 2006 at 02:46 PM.

  2. #2
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    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:
    1. Option Explicit
    2.  
    3. Private db As Database
    4. Private rs As Recordset
    5. Private ws As Workspace
    6.  
    7. Private Sub Form_Load()
    8.  
    9. Set ws = DBEngine.Workspaces(0)
    10. Set db = ws.OpenDatabase(App.Path & "\db.mdb")
    11. Set rs = db.OpenRecordset("user_info", dbOpenTable)
    12.  
    13. End Sub
    14.  
    15. 'place the rest of your subs down here

    I use ADODB.
    With it you have to use the NEW command like this.
    VB Code:
    1. Set rs = New ADODB.Recordset
    Last edited by longwolf; Dec 17th, 2006 at 03:54 PM.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    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...

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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:
    1. Public db As Database
    2. Public rs As Recordset
    3. Public ws As Workspace

  5. #5
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    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

  6. #6
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: New User : VB6 Project : Database Problem

    Oh, BTW, Welcome to the Forum!

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    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

  8. #8
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    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..

  10. #10
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width