Results 1 to 7 of 7

Thread: Unbound form...

  1. #1
    Join Date
    Oct 2004
    Posts
    57

    Unanswered: Unbound form...

    this should be easy....
    I have an unbound form...I want an On Click event to open a table, create a new record and write several fields from the form to the table. Any help would be appreciated....

  2. #2
    Join Date
    Dec 2003
    Posts
    268
    Quote Originally Posted by Geremia
    this should be easy....
    I have an unbound form...I want an On Click event to open a table, create a new record and write several fields from the form to the table. Any help would be appreciated....
    You are going to want to use some SQL to accomplish this. Look at the INSERT command through your help.

    INSERT INTO table (fields, fields) VALUES (values, values)

  3. #3
    Join Date
    Oct 2004
    Posts
    57
    Thanks for the help but I'm having some real problems with the formatting....
    I have 2 Strings (strA and strB) that I want to enter into Fld1 & Fld2 in TblA...Can you help?

    Also, does anyone know if this can be accomplished using ADO??(I'm curious....)

  4. #4
    Join Date
    Sep 2004
    Location
    Tampa, FL
    Posts
    520
    Something along this line between your Subs.

    Code:
    Dim SQL as string
    SQL = "UPDATE Table SET Table.FieldA = forms!yourform!StrA, Sql & Table.[FieldB] = forms!yourform!StrB"
    DoCmd.RunSQL SQL

    Helpfull I hope.
    Darasen

  5. #5
    Join Date
    Nov 2004
    Posts
    32

    embeding SQL

    I think that you will have to take Darsens suggestion a little further because the SQL statement will be looking for a string and when useing the value of a control directly in the statement it is just like using a string variable. so the SQL statement will have to go something like this

    SQL = "UPDATE Table SET Table.FieldA = '" & forms!yourform!StrA & "', " Table.[FieldB] = '" & forms!yourform!StrB & "'"

    that way you are concatenating the variables into the SQL statement which is a string and when revering to a string value within that statement you use a single quote ' instead of a double quote "

    I hope that helps

    Cheers
    Tim

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    although its no bad thing to fully qualify your variable names you can be more idle and use
    SQL = "UPDATE Table SET Table.FieldA = '" & StrA & "', " Table.[FieldB] = '" & StrB & "';"

    to avoid the problems of enclosing strings varaibles in SQL if often resort to

    SQL = "UPDATE Table SET Table.FieldA = " & chr$(34) & StrA & chr$(34) & ", "& chr$(34) & Table.[FieldB] = '" & StrB & chr$(34) &";"

    its also advisable to end your sql with a semi colon, sometimes JET understands, sometimes it gets snotty, so I'd reccomend that you always end SQL statements with a semi colon.

  7. #7
    Join Date
    Oct 2004
    Posts
    57
    thanks for the advise guys....i figured it out with ADO...but I think its time I learn how to insert sql into VBA....

Posting Permissions

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