Results 1 to 12 of 12

Thread: Load blank fields using ADODC?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2015
    Posts
    80

    Load blank fields using ADODC?

    Hi,
    I am using ADODC control for my project's form.

    I am having two different forms, one for adding new records and one for viewing and deleting the records.


    My question is, when I load the ADODC form for submitting new records, all the textboxes should be blank, currently they load data from the first record in them.
    How do I achieve this? I want the textboxes to remain blank.

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: Load blank fields using ADODC?

    1-welcome to the forum
    2-Why use the ADODC control? Why not just ADO and display your data in some form of a grid or series of textboxes?
    3-Kinda need to see your code or project. If the project is small and does not contain sensitive information, go ahead and attach it in zipped format.

    Apprears you are just learning. PERSONALLY, I would steer away from the ADODC control. Am not sure what textboxes you are referring to.

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Load blank fields using ADODC?

    I am assuming those text boxes are bound to the control so they show the data of the active record.

    If you want to add a new record then you need to use the .addnew method

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2015
    Posts
    80

    Re: Load blank fields using ADODC?

    Quote Originally Posted by SamOscarBrown View Post
    1-welcome to the forum
    2-Why use the ADODC control? Why not just ADO and display your data in some form of a grid or series of textboxes?
    3-Kinda need to see your code or project. If the project is small and does not contain sensitive information, go ahead and attach it in zipped format.

    Apprears you are just learning. PERSONALLY, I would steer away from the ADODC control. Am not sure what textboxes you are referring to.
    Quote Originally Posted by DataMiser View Post
    I am assuming those text boxes are bound to the control so they show the data of the active record.

    If you want to add a new record then you need to use the .addnew method

    Thank you for the quick responses.
    I am going to be on this forum for a long time I believe.

    Yes, I am in fact learning.
    All I want is that when I load the form, all the text fields should be empty.
    And when I fill in those text fields and click add, a new entry should be made in the database.

    The second one I have achieved. All I want to is to keep the text fields blank upon loading the form.
    How do I achieve this?

    Thank you.

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: Load blank fields using ADODC?

    As the ADODC control is tied directly to your table, it will show the active record (see DataMiser's post).

    Why don't you upload your zipped project (without any .exe files) and I'll take a look and provide you with some assistance to make sure your textboxes are indeed blank upon start up...but I need to see HOW you are using the control, what textboxes you are talking about, and what your database looks like.

    To upload your zipped file, go to the "Go Advanced" button and then select "Manage Uploads" and follow the process.

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Load blank fields using ADODC?

    Its been so long since I have used a bound textbox I can't remember if they all just blank out automatically when .addnew is called or if you need to write code to blank them out.
    I am thinking now that you probably need code to blank them out which of course is simply setting the text of each textbox to an empty string.

    Seems odd to have a different form for adding a new record though. Normally you would add and edit on the same form

  7. #7
    Addicted Member masoudk1990's Avatar
    Join Date
    Nov 2013
    Location
    Persia
    Posts
    172

    Re: Load blank fields using ADODC?

    When you bind your fields to a control cant you simply set your controls to blank? Or they show value of active record again?

    Code:
    Form_Load()
    
          '
          '
          'various codes
          '
          '
    
          'if its possible simply set your text boxes to blank before end sub
          textbox1.text = ""
          textbox2.text = ""
          textbox3.text = ""
    
    End sub
    Last edited by masoudk1990; Aug 8th, 2015 at 04:33 AM.
    Computer Enterprise Masoud Keshavarz
    For more information contact masoudk1990@yahoo.com

  8. #8
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Load blank fields using ADODC?

    Please do not use the following -
    - Data Environment (I don't think you have, but this is for future readers)
    - Data Controls
    - Binding

    Rob

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Load blank fields using ADODC?

    Whatever you do, avoid multiple ADODCs in one program that open the same database. It gets clunky and expensive because each separate connection means more overhead behind the scenes.

    For you scenario of a "new record" form you probably don't want to use bound controls at all, since that isn't what they're for. They work fine in an "add new" scenario as expressed already in post #3 above. However this can have issues: the ADODC's embedded Recordset isn't really meant to be fiddled with a lot. Sometimes it is the only way to go, but pretty quicly you may find it more trouble and a straight code approach works better.

    Another possibility is unbound controls and then calling the Execute method on the embedded Recordset's ActiveConnection property. But that's even deeper into "fiddling" territory.


    The classic answer to this is to just throw away the ADODC and use a DataEnvironment instead. The DataEnvironment is like an ADODC on steroids, and can support connections to multiple databases as well as multiple commands on each one. You get all sorts of designers, SQL-builders, and easily constructed parameter queries.

    Of course a lot of self-taught plinkers fear and loathe all of this because it can be a deep mystery to the untrained. They'd have had no chance at all to pass the old VB6 MCSD exam because this and many other topics they shun were required.


    Here's a simple demo (attached). The size of the attachment is mostly from the icons that are used there!

    There is a small CreateDb program you run first to create a simple Jet database with some sample data.

    Then there is a UseDb program which opens with a main DataGrid form allowing viewing and row deletes, and it has a button to add a new row. This button opens a second form with empty fields to enter data into.

    The DataGrid on the main form is bound to a DECommand named AllData. The "Save" button on the secondary form calls a DECommand named NewRow, passing it the entered values from the unbound fields.

    As a result there is almost no code here at all once you disregard all of the UI-management stuff.
    Attached Files Attached Files

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Aug 2015
    Posts
    80

    Re: Load blank fields using ADODC?

    Quote Originally Posted by SamOscarBrown View Post
    As the ADODC control is tied directly to your table, it will show the active record (see DataMiser's post).

    Why don't you upload your zipped project (without any .exe files) and I'll take a look and provide you with some assistance to make sure your textboxes are indeed blank upon start up...but I need to see HOW you are using the control, what textboxes you are talking about, and what your database looks like.

    To upload your zipped file, go to the "Go Advanced" button and then select "Manage Uploads" and follow the process.
    Quote Originally Posted by DataMiser View Post
    Its been so long since I have used a bound textbox I can't remember if they all just blank out automatically when .addnew is called or if you need to write code to blank them out.
    I am thinking now that you probably need code to blank them out which of course is simply setting the text of each textbox to an empty string.

    Seems odd to have a different form for adding a new record though. Normally you would add and edit on the same form
    Quote Originally Posted by masoudk1990 View Post
    When you bind your fields to a control cant you simply set your controls to blank? Or they show value of active record again?

    Code:
    Form_Load()
    
          '
          '
          'various codes
          '
          '
    
          'if its possible simply set your text boxes to blank before end sub
          textbox1.text = ""
          textbox2.text = ""
          textbox3.text = ""
    
    End sub
    Quote Originally Posted by Bobbles View Post
    Please do not use the following -
    - Data Environment (I don't think you have, but this is for future readers)
    - Data Controls
    - Binding

    Rob
    Quote Originally Posted by dilettante View Post
    Whatever you do, avoid multiple ADODCs in one program that open the same database. It gets clunky and expensive because each separate connection means more overhead behind the scenes.

    For you scenario of a "new record" form you probably don't want to use bound controls at all, since that isn't what they're for. They work fine in an "add new" scenario as expressed already in post #3 above. However this can have issues: the ADODC's embedded Recordset isn't really meant to be fiddled with a lot. Sometimes it is the only way to go, but pretty quicly you may find it more trouble and a straight code approach works better.

    Another possibility is unbound controls and then calling the Execute method on the embedded Recordset's ActiveConnection property. But that's even deeper into "fiddling" territory.


    The classic answer to this is to just throw away the ADODC and use a DataEnvironment instead. The DataEnvironment is like an ADODC on steroids, and can support connections to multiple databases as well as multiple commands on each one. You get all sorts of designers, SQL-builders, and easily constructed parameter queries.

    Of course a lot of self-taught plinkers fear and loathe all of this because it can be a deep mystery to the untrained. They'd have had no chance at all to pass the old VB6 MCSD exam because this and many other topics they shun were required.


    Here's a simple demo (attached). The size of the attachment is mostly from the icons that are used there!

    There is a small CreateDb program you run first to create a simple Jet database with some sample data.

    Then there is a UseDb program which opens with a main DataGrid form allowing viewing and row deletes, and it has a button to add a new row. This button opens a second form with empty fields to enter data into.

    The DataGrid on the main form is bound to a DECommand named AllData. The "Save" button on the secondary form calls a DECommand named NewRow, passing it the entered values from the unbound fields.

    As a result there is almost no code here at all once you disregard all of the UI-management stuff.


    Thank you for all your support everyone! You all helped. +rep to everyone!


    How ever, I am having one issue.
    When I click add to add the record it doesn't add the record in the database sometimes.
    Sometimes it does, sometimes it doesn't.
    Why is this happening? I have no idea. Any way to debug?

  11. #11
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Load blank fields using ADODC?

    Without more info it is hard to say. Haven't saw your code and don;t know what rules may be on the db.
    If you are trying to update something with an invalid value it will fail. If you try to put a dupe value in a field that does not allow dupes it will fail. If you omit a value for a field that requires a value it will fail.
    All of these should give an error but if like many who post here you are using On Error Resume next then you will not see the error when it happens, it just won't work.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Aug 2015
    Posts
    80

    Re: Load blank fields using ADODC?

    Quote Originally Posted by DataMiser View Post
    Without more info it is hard to say. Haven't saw your code and don;t know what rules may be on the db.
    If you are trying to update something with an invalid value it will fail. If you try to put a dupe value in a field that does not allow dupes it will fail. If you omit a value for a field that requires a value it will fail.
    All of these should give an error but if like many who post here you are using On Error Resume next then you will not see the error when it happens, it just won't work.


    Actually I made another thread with more info in this same section. A moderator will have to approve it before it is visible to you guys.

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