DBGRID refresh

I am using vb6.0 and access97. i have 2 tables. A and B. I am trying to make a purchase order program that when you hit the button new it assigns a number to the next order. Now when i run this code i get a refresh error. The access table i connect to has a count field. But i don't know why i get a refresh error.I want the dbgrid to be the details of different orders but with the same assigned order number

Private sub datproducts_reposition()
 dim strsql as string
if datproducts.recordset.recordcount = 0 then
exit sub
end if
strsql = "select * from [order details] where productid = " & datproducts.recordset.fields("productid")
datorderdetails.recordsource = strsql
datorderdetails.refresh
dbgorderdetails.columns("productid").defaultvalue = datproducts.recordset.fields("productid")
end sub
jbird090897Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vettrangerCommented:
Here's some code that I took directly from a working project that does the same thing. I've modified it to use your naming details. Note that I've taken the space out of your OrderDetails table ... its bad practice to included imbedded spaces in either table or field names.

Temp$ = datProducts.Recordset!ProductID
q$ = "Select * from OrderDetails where ProductID = " & Chr(34) & Temp$ & Chr(34)
'if ProductID is a numeric field, then
'use the following line
'q$ = "Select * from OrderDetails where ProductID = " Temp$

datOrderDetails.RecordSource = q$
datOrderDetails.Refresh
dbgOrderDetails.Refresh

If this code doesn't work, please post the exact error number and message you are getting, as well as the line program execution is stopping on.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vettrangerCommented:
The commented select statement should be :

'q$ = "Select * from OrderDetails where ProductID = " & Temp$

Sorry about that, I deleted one to many ampersands!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.