Adodc and VB6 problems...

linkgoron

Platinum Member
Mar 9, 2005
2,593
1,236
136
Well, I'm making a hospital program, and I want to have a patient's list on the doctor's-edit screen.
So this what I wrote:

FrmAdd.Txtfirname.Text = frmWorker.AdoWorker.Recordset![WorkerFirName]
FrmAdd.txtlastname.Text = frmWorker.AdoWorker.Recordset![workerfamname]
FrmAdd.TxtWorkerHours.Text = frmWorker.AdoWorker.Recordset![workerhours]
FrmAdd.CmbWorkType.AddItem frmWorker.AdoWorker.Recordset![workertype]
Adopatients.RecordSource = "select * from TblPatient where DoctorId = " & Val(TxtId.Text)
Adopatients.Refresh

Well, it crashes after the adopatients.refresh line. Message "Syntex Error in From clause". So i looked in some SQL guides, and it looked ok. What am I doing wrong?
 

KB

Diamond Member
Nov 8, 1999
5,406
389
126
Why use the Val function:
"select * from TblPatient where DoctorId = " & TxtId.Text
should work fine.

Your SQL looks ok to me.
Double-check your spelling on the Table (TblPatient) and DoctorID. Make sure DoctorID is a number field.
 

linkgoron

Platinum Member
Mar 9, 2005
2,593
1,236
136
DoctorID is a number and TblPatient is also correct. Are you sure that my SQL is correct?

Tried it without VAL, still didn't work.
Oh, maybe this is important.It also says that "method 'Refresh' of object of object 'IAdodc' failed." Run-time error'-2147217900(80040e14)

EDIT
I looked this up in the MSDN, and this is what I found:
http://support.microsoft.com/kb/238279/en-us

So i added this:
FrmAdd.adoadd.Recordset.Bookmark = frmWorker.AdoWorker.Recordset.Bookmark
FrmAdd.TxtId.Text = frmWorker.AdoWorker.Recordset![WorkerId]
FrmAdd.Txtfirname.Text = frmWorker.AdoWorker.Recordset![WorkerFirName]
FrmAdd.txtlastname.Text = frmWorker.AdoWorker.Recordset![workerfamname]
FrmAdd.TxtWorkerHours.Text = frmWorker.AdoWorker.Recordset![workerhours]
FrmAdd.CmbWorkType.AddItem frmWorker.AdoWorker.Recordset![workertype]
FrmAdd.Adopatients.CommandType = adCmdtext
FrmAdd.Adopatients.RecordSource = "select * from TblPatient where doctorid=" & Val(TxtId.Text)
Adopatients.Refresh
DG2.Refresh
and now it works. But it's kind of dumb, and I don't know if it's ok. What do you guys think?
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
"method 'Refresh' of object of object 'IAdodc' failed." Run-time error'-2147217900(80040e14)

Probably because ADOPatients isn't set to an instance of an object. Is there anything you need to do like load a database before you use it? Try loading it at runtime prior to the Refresh call.