|
-
Apr 27th, 2006, 06:33 AM
#1
Thread Starter
Addicted Member
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
-
Apr 27th, 2006, 10:05 AM
#2
Frenzied Member
Re: How to link textboxes to SQL strings ??
VB Code:
' In code
"UPDATE tlbPartsTable SET tlbPartsTable.ItemsInStock = " & _
"[tlbPartsTable].[ItemsInStock]- " & _
Val(frmReqTransaction.txtQuantity.Text) & _
" WHERE ((([tlbPartsTable].[PartID])= " & _
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
-
Apr 28th, 2006, 12:59 AM
#3
Thread Starter
Addicted Member
Re: How to link textboxes to SQL strings ??
Can the same code be implemented in Access using the script editor and not VB6. ??
-
Apr 28th, 2006, 06:35 AM
#4
Frenzied Member
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
-
Apr 28th, 2006, 07:46 AM
#5
Thread Starter
Addicted Member
[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.
-
Apr 28th, 2006, 09:34 AM
#6
Frenzied Member
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
-
Apr 28th, 2006, 09:39 AM
#7
Addicted Member
Re: How to link textboxes to SQL strings ??
This is because the DBEngine does not recognize what "frmReqTransaction.txtPartID" is.
VB Code:
'Try replacing frmReqTransaction.txtPartID with
Forms("frmReqTransaction")!txtPartID ' or
[Form_frmReqTransaction]!txtPartID ' or
Forms!frmReqTransaction!txtPartID
' 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...
-
Apr 28th, 2006, 09:42 AM
#8
Addicted Member
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!
-
Apr 29th, 2006, 04:19 AM
#9
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|