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

Connecting to database using ADO

Status
Not open for further replies.

MikeWare

Programmer
Sep 25, 2002
5
CA
Hiya

I get a run-time error No value for one or more the given parameters when running the following code.

Im running VB6 SP3 and trying to connection a Access 2000 db

Any help would be great.....this is the code ->

Private sub cmdTest_click

Dim objPatient As New clsPatient 'set new instance of object

On Error GoTo Error_Handler

CommonDialog1.DialogTitle = "Select a database"
CommonDialog1.Filter = "Access Files (*.mdb)|*.mdb"
CommonDialog1.InitDir = "C:\Test\"
CommonDialog1.FilterIndex = 1
CommonDialog1.Flags = cdlOFNFileMustExist + _
cdlOFNLongNames cdlOFNOverwritePrompt

CommonDialog1.ShowOpen

If CommonDialog1.FileName <> &quot;&quot; Then
Set gcnDatabase = New ADODB.Connection
gcnDatabase.Provider = &quot;Microsoft.jet.OLEDB.4.0&quot;
gcnDatabase.Mode = adModeReadWrite
gcnDatabase.Open CommonDialog1.FileName
End If

objPatient.Load 4960 'Call the object

exit sub

Error_Handler:

end sub
____________________________________________________________
This is the code in the object:

Option Explicit

Private mflgLoading as boolean

Public Sub Load(Optional lngPatientKey As Long)

If mflgLoading Then Err.Raise 455

Loading
Fetch lngPatientKey
EndLoading

End Sub


Private Sub Fetch(lngStaffKey As Long)

Dim rsFetchRecord As ADODB.Recordset
Dim strSQL As String

Set rsFetchRecord = New ADODB.Recordset

strSQL = &quot;&quot;
strSQL = strSQL & &quot;SELECT * FROM Staff &quot;
strSQL = strSQL & &quot;WHERE [StaffKey] = &quot; & lngStaffKey

rsFetchRecord.Open strSQL, gcnDatabase, adOpenDynamic, adLockOptimistic

With rsFetchRecord
If Not (.BOF And .EOF) Then
mudtProps.PatientKey = !PatientKey
mudtProps.Surname = !Surname
End If
End With

Set rsFetchRecord = Nothing

End SubPrivate Sub Loading()

mflgLoading = True

End Sub

Private Sub EndLoading()

mflgLoading = False

End Sub

____________________________________________________________
Thanks in advance

Mike
 
Oh sorry forgot to mension

gcnDatabase is a Variable in another module...

Public gcnDatabase = adodb.connection

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top