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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB DATA COMBO BOX AND SQL

Status
Not open for further replies.

morlassino

IS-IT--Management
Jul 1, 2004
33
0
0
US
i have maybe a simple question please forgive my stupidity in advance. I am new to VB and i have programmed in VFP but i need to switch to VB. anyway i have two tables on SQL Server one is the parent and othe ris a details my question is that i would like to use a datacombo box to choose a date from the parent to open a datagrid box with the records that only match the date i selected in the datacombo box. i have attempted with failure here is the code i used
Code:
Private Sub DataCombo1_Change()

pstrselect.Open = "SELECT date from brkdetails WHERE date = '" & DataCombo1.Text & "'"
pstrsql = pstrselect
    Adodc1.RecordSource = pstrsql
    Set DataGrid1.DataSource = pstrsql
    Adodc1.Refresh

End Sub>

MARIO P ORLASSINO
ASSISTANT MANAGER IT
"THE HOSE HEAD"
 
If it's a date field then use this instead...

Code:
pstrselect.Open = "SELECT date from brkdetails WHERE date = #" & DataCombo1.Text & "#"

Hope this helps,

Patrick
 
i now get an error object required.. i am at a lost
Code:
 pstrselect.Open = "SELECT date from brkdetails WHERE date = #" & DataCombo1.Text & "#"
i get error object required
with
Code:
pstrselect = "SELECT date from brkdetails WHERE date = #" & DataCombo1.Text & "#"
i get "incorect syntax next to "SELECT"
thanks for your help





MARIO P ORLASSINO
ASSISTANT MANAGER IT
 
Yeah figured as much, I think date is a reserved word in SQL, you'll have to change the name of the field.
 
i changed the name of the field on both tables to dateid and still same thing


MARIO P ORLASSINO
ASSISTANT MANAGER IT
 
Sorry to ask but did you change the SELECT statement also?
 
I thank you i got it to work i needed to remove the # signs that caused an error.
but what had happened is the record source for the adodc1 was set to a table and then i was forcing to change once i put a sql statement in the record source on the properties of the adodc1 it worked that you for all the advice i am sure we will speak again and you helped me think a bit harded thats how i figured this out...

thanks again


MARIO P ORLASSINO
ASSISTANT MANAGER IT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top