Results 1 to 8 of 8

Thread: Add new records

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132

    Red face

    How can i add new records using DAO without making it confusing for the user?
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    Could you be a little more specific about what you want to let the end-user do? And/or define what it is about your current method that you understand is confusing. If you know the table, fields you intend letting the end-user insert, it's one thing; but if you are trying to allow the end-user to input SQL directly, it's another. With better def, I would be happy to give you my two cents worth

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    i know the fields and the table all that the end user has to do is enter the info. See thread http://forums.vb-world.net/showthrea...threadid=23036 for specifics
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  4. #4
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    Sorry for the delay in responding, I got sidetracked.

    It doesn't have to be much more exotic than something like this:
    Code:
    Sub AddNewRec_Click()
    Dim SQL$, db as database
      On Error Goto Oops 
      ' when textbox values are error free
      SQL$ = "INSERT <table_name>(<field1_name>, <field2_name>)VALUES('" & tb1_str & "', " tb2_int & ")" 
      Set db = OpenDatabase(<yourdatabase>) 
      db.execute SQL$
      Set db = Nothing
      ' refresh supporting data form/object, as necessary, to show new data
      ' since end-user "sees" none of this, maybe add msgbox saying life is good
      Exit Sub
    Oops:
      ' maybe say the wheels flew off..
    End Sub
    * pesky smiley faces, always forget to uncheck that box...
    And my SERIOUS headspace-timing being out of sync isn't helping either...

    [Edited by Mongo on 07-16-2000 at 01:35 AM]

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132

    in the line SQL$ etc..where it says tb1_str and tb2_int can i put text boxes eg txtband.text instead?
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  6. #6
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    Yes. Sorry I got too short in my shorthand naming. I was trying to imply a textbox.text value that is supposed to be a string with tb1_str (note the extra tick marks on each side) and an integer datatype with tb2_int.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132


    :grin:

    Thank you...

    um the values weren't entered into the TABLE.

    do i need the field names in brackets after the table name in the SQL line?
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  8. #8
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    Jimminey Cricket, I am running on empty. Yes! When you are not including ALL table def fields in your insert or they are out of order, you must specify the field names.

    And I meant the <> as generic signifiers, you DO NOT include them.

    INSERT table_name(fieldA_name,fieldB_name)VALUES("IF DOPE USE ODD", 1)

    [Edited by Mongo on 07-16-2000 at 01:37 AM]

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