Variables and Queries

NoMAd

Registered User.
Local time
Tomorrow, 08:08
Joined
Oct 31, 2004
Messages
17
Sorry if this has already popped up..

Umm.. i need help with an insert query, but i have to use vb for it..

STORY... I SPOSE..
Its a computer part shopping cart basically..
when a user logs in, a column in the user table called 'active' is set to YES, since its a yes/no field.
When a user goes to add a product to his cart is when i have trouble... it wouldnt be so bad if i didnt have active users... but.. i do.. Basically i want to know how to insert the part/parts into the cart which is owned by this active user.

can anyone help me?
 
usually you have a shopping cart table that contains the items in their "cart". But you must have a key to tie the items back to the user. You must also be aware the user could add items, then leave and come back in a year and won't want those items in their "cart". Your typical shopping cart table would contain key/s to tie an item to the cart, and a key/s to tie the cart to a person. usually a qty and price field, plus date time added (at a minimum). Then how you handle something like checking out adds more or less to it.
Just for starters.
 
ok.. but that doesnt answer my question.. i want to know how to add to their "cart" when they are active... like it finds which user is active and puts it in their cart..

thanks anyway
 
NoMAd,

Your s/w should just wait for a user.

When someone launches your app:

1) Register (login, whatever) - CurrentUserID
2) Grab cart(s) - CartID(s)
3) Select Merchandise - put in Cart

Code:
DoCmd.RunSQL "Insert Into tblTransaction(UserID, CartID, MerchandiseID, Quantity) " & _
             "Values(" & Me.CurrentUserID & ", " & _
                         Me.CartID & ", " & _
                         Me.MerchandiseID & ", " & _
                         Me.Quantity & ");"

The "Me." things just refer to controls on your form(s).

You could also physically map your controls to your user/cart/order tables and
not use VBA at all.

Wayne
 
Thanks WayneRyan

It worked for a second but then something happened.

DoCmd.RunSQL "Insert Into cartcontent( User, qty, product) " & _
"Values(" & Me.CurrentUser & ", " & _
Me.text2 & ", " & _
Me.list24 & ");"

i used that, but it gave me a "syntax error with the insert into statement" can someone help
 
NoMAd,

Punctuation:

Delimiters for SQL - Date(#), String('), Number(nothing)

Insert a date, text, text, number (forget their names, just an example:

Code:
DoCmd.RunSQL "Insert Into tblTransaction(UserID, CartID, MerchandiseID, Quantity) " & _
             "Values(#" & Me.CurrentUserID & "#, '" & _
                          Me.CartID & "', '" & _
                          Me.MerchandiseID & "', " & _
                          Me.Quantity & ");"

Takes a little getting used to, SQL wants:

Code:
Insert Into tblTransaction (UserID, CartID, MerchandiseID, Quantity) 
Values(#11/11/2004#, 'Cart12', 'SomeJunk', 15)

YOU have to provide the punctuation to help it.

Wayne
 
hey thanks that works.. i have another problem now..

how do you make a list box automatically select the top row once it's run its query?
 
NoMAd,

This Selects them all:

Code:
Dim lngTable As Long
  For lngTable = 0 To Me.lstTables.ListCount - 1
     Me.lstTables.Selected(lngTable) = True
     Next lngTable
End Sub

The 1st would be Me.lstTables.Selected(0) = True

Wayne
 
yeah thats mad.. but is there ne way to make it like its just been clicked?
 
NoMAd,

Sure, If you explicitly requery it, just that line of code after the requery.
Or use any other event line the form's OnCurrent, or some Command Button.

Wayne
 

Users who are viewing this thread

Back
Top Bottom