Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Into Table from Unbound Textbox 1

Status
Not open for further replies.

techsponge

Technical User
Feb 8, 2006
37
US

I am creating an application to sell games.

Users pick from a list of games on frmBowl20 (only one game may be sold at a time).

When the user clicks the "Sell" image on the form (frmBowl20)I transfer the main game details to unbound controls on the unbound form that acts like a cash register 'frmSalesReg.


My question is how would I go about writting the information in the unbound text boxes to my table?

frmSalesReg unbound controls:

washstampnum
QtySold
TktValue
SoldBy
DateSold
TotalSale
Binnum

[TblTicketSales]

washstampnum
QtySold
TktValue
SoldBy
DateSold
SaleID (this is autonumbered)
TotalSale
Binnum


Many thanks as always

 
use SQL.

DoCmd.RunSQL "INSERT INTO tblTicketSales ........



-Pete
 
techsponge,

Sounds like a job for an append query... You could build a query in the query design grid, using your form fields as criteria, then launch from a command button. Or you could write your SQL in code and also launch from a command button (or you could do it all at once when the user clicks on the Sell image). Something like this (air code, untested):
Code:
Dim strMySQL As String

strMySQL = "INSERT INTO TblTicketSales " _
& "(washstampnum, QtySold, TktValue, SoldBy, DateSold, TotalSale, Binnum) " _
& "VALUES (" & Me!washstampnum & ", " & Me!QtySold & ", " & Me!TktValue & ", '" _
& Me!SoldBy & "', #" & Me!DateSold & "#, " & Me!TotalSale & ", " & Me!Binnum & ")"

DoCmd.RunSQL strMySQL

Note that in VBA SQL strings, numeric field values require no delimiter, text values are enclosed in single quotes, and dates are enclosed by the pound sign.

HTH,

Ken S.
 
I tried the following and get error 3134?

Any ideas?

Private Sub Enter_Click()
DoCmd.RunSQL "INSERT INTO TblTicketSales (washstampnum, tktcount, value, username, Date(), total, binnum)"

DoCmd.Close acForm, "frmSalesReg"
End Sub
 
techsponge,

Your SQL statement is incomplete, see my post above. Also, there seems to be a discrepancy between the field names listed in your first post and those in your code.

Ken S.
 
Pete (snyperX3):
Could you revisit your response to the post Function Converting Text? I'm not sure where to put the code snipet you gave me... Sorry to horn in, but it looks like you have moved on and I still need clarification.

Tom
 
Eupher,

Great info and loved the explination of text vs.umbers and dates.

A star for you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top