Results 1 to 9 of 9

Thread: How to link textboxes to SQL strings ??

  1. #1

    Thread Starter
    Addicted Member arunb's Avatar
    Join Date
    Jul 2005
    Posts
    131

    How to link textboxes to SQL strings ??

    Hi,

    How do I link the values in a textbox on a form to an entry in the SQL string.

    For example:

    UPDATE tlbPartsTable SET tlbPartsTable.ItemsInStock =

    [tlbPartsTable].[ItemsInStock]-frmReqTransaction.txtQuantity
    WHERE ((([tlbPartsTable].[PartID])=frmReqTransaction.txtPartID));

    Here frmRequistion is the form (It is not linked to any data source)...
    txtQuantity, txtPartID are textboxes...
    tlbPartTable is the table where data is retrieved....

    thanks
    arun

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: How to link textboxes to SQL strings ??

    VB Code:
    1. ' In code
    2. "UPDATE tlbPartsTable SET tlbPartsTable.ItemsInStock = " & _
    3. "[tlbPartsTable].[ItemsInStock]- " & _
    4. Val(frmReqTransaction.txtQuantity.Text) & _
    5. " WHERE ((([tlbPartsTable].[PartID])= " & _
    6. Val(frmReqTransaction.txtPartID)));
    This assumes your fields in the table are numeric, which is reasonable since you're subtracting them. The values in your textboxes are string data types, which can't be subtracted, or compared meaningfully, from numeric data types. You have to convert them. You could use CInt(), CDbl(), etc., instead of Val() if needed.
    Also make sure of your tablename -tbl is the usual prefix, not tlb.
    Tengo mas preguntas que contestas

  3. #3

    Thread Starter
    Addicted Member arunb's Avatar
    Join Date
    Jul 2005
    Posts
    131

    Re: How to link textboxes to SQL strings ??

    Can the same code be implemented in Access using the script editor and not VB6. ??

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: How to link textboxes to SQL strings ??

    If by script editor you mean VBA, yes, that's how I'd do it. You could also create it as a saved query, without the double quotes.
    Tengo mas preguntas que contestas

  5. #5

    Thread Starter
    Addicted Member arunb's Avatar
    Join Date
    Jul 2005
    Posts
    131

    [RESOLVED]How to link textboxes to SQL strings ??

    Thanks a lot it worked well.

    I changed the string to

    UPDATE tblPartsTable SET tblPartsTable.ItemsInStock = [tblPartsTable].[ItemsInStock]-Val([Forms]![frmReqTransaction]![txtQuantity])
    WHERE ((([tblPartsTable].[PartID])=[Forms]![frmReqTransaction]![txtPartID]));

    It seems the Forms! entry removed the Parameter Dialog box and I could get the values straight away from the textboxes.

    Will post further questions if required....

    thanks
    arunb
    Last edited by arunb; Apr 28th, 2006 at 09:23 AM.

  6. #6
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: How to link textboxes to SQL strings ??

    Great. If this is VBA code in an event procedure of the form, you can replace Forms with Me.
    Tengo mas preguntas que contestas

  7. #7
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: How to link textboxes to SQL strings ??

    This is because the DBEngine does not recognize what "frmReqTransaction.txtPartID" is.

    VB Code:
    1. 'Try replacing frmReqTransaction.txtPartID with
    2. Forms("frmReqTransaction")!txtPartID ' or
    3. [Form_frmReqTransaction]!txtPartID ' or
    4. Forms!frmReqTransaction!txtPartID
    5. ' all of these reference the same textbox

    If this doesn't work, you may have to create a table that is the data source for frmReqTransaction. Because your textbox value may be temporary, storing the textbox value in a table will provide a way for you to access the data via a SQL string. You can even accomplish this by having only one record in that table, and overwriting the values for that one record every time your form is changed (using events).

    Hope this helps...

  8. #8
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: How to link textboxes to SQL strings ??

    I guess I didn't read your last post closely enough... good job on getting it to work!

  9. #9

    Thread Starter
    Addicted Member arunb's Avatar
    Join Date
    Jul 2005
    Posts
    131

    Re: How to link textboxes to SQL strings ??

    I would like to now modify the sql string

    UPDATE tblPartsTable SET tblPartsTable.ItemsInStock = [tblPartsTable].[ItemsInStock]-Val([Forms]![frmReqTransaction]![txtQuantity])
    WHERE ((([tblPartsTable].[PartID])=[Forms]![frmReqTransaction]![txtPartID]));

    so that entries like txtQuantity, txtPartID are inserted in a new record in another table tblRequistions, this table initially contains just one record.

    So now if the sql query finds a matching PartID, the entries like txtQuantity, txtPartID are added to a new record in the tblRequistions table. In case of unmatched PartID no entry should be made.

    I am not sure if this will work, I checked out some previous threads an there i says that an Insert and Update command cannot be performed in a single sql query string.. Is this so ???

    Kindly advise what other methods exist???

    thanks
    arun

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