-
VB6 Halp required
Hey guys im designing a system to search a MS Access database and I just cant seem to get it working.
Dim key As String, str As String
Dim count, a As Integer
count = frmAdmin.Adodc1.Recordset.RecordCount
key = " "
key = InputBox("Enter the policy No whose details u want to know: ")
'For a = 1 To count
'If key = frmAdmin.Adodc1.Recordset.Fields(0) Then
'Call MsgBox("Client Exists", vbOKOnly + vbInformation, "Client Exists")
'Else
'Call MsgBox("client does not exist", vbOKOnly + vbInformation, "Client does not exist")
' End If
'Next a
'str = "select * from Client where [Policy Number]=" & key
'frmAdmin.Adodc1.Recordset.Open str
'frmAdmin.Adodc1.Recordset.Close
While Not (frmAdmin.Adodc1.Recordset.EOF) And found = False
If frmAdmin.Adodc1.Recordset.Fields(0) = key Then
Call MsgBox("record exists", vbOKOnly + vbInformation, "Record found")
found = True
Else
Call MsgBox("record does not exist", vbOKOnly + vbInformation, "record not found")
End If
frmAdmin.Adodc1.Recordset.MoveNext
Wend
thats the code Im currently using. as you can see Im using ADODC and I even tried using SQL to no avail...Please assist....
-
Re: VB6 Halp required
Welcome to VBForums.com :wave:
Will this help you...??? :)
Code:
'set up the recordset, and load the data:
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "SELECT Client where Policy_Number= '" & strKey & "'", cn, adOpenStatic, adLockReadOnly, adCmdText
If rs.EOF Then
MsgBox "No data found!"
Else
'..do what we want with the data in this record
MsgBox rs.Fields("field1").Value
End If
'tidy up
rs.Close
Set rs = Nothing
Also, view this thread:
http://www.vbforums.com/showthread.php?t=416218
Good luck.. :)
-
Re: VB6 Halp required
Dim key As String, str As String
Dim count, a As Integer
count = frmAdmin.Adodc1.Recordset.RecordCount
key = " "
key = InputBox("Enter the policy No whose details u want to know: ")
'set up the recordset, and load the data:
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "SELECT Client where Policy_Number= '" & key & "'", adOpenStatic, adLockReadOnly, adCmdText
If rs.EOF Then
MsgBox "No data found!"
Else
'..do what we want with the data in this record
MsgBox rs.Fields("field1").Value
End If
'tidy up
rs.Close
Set rs = Nothing
End Sub
the error im getting is Run time error 3001: Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
HELP....
-
Re: VB6 Halp required
You have to include the connection also...
Code:
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= " & App.Path & "\abc.mdb"
cn.Open
Make sure, you had added reference to Microsoft ActiveX Data Objects
-
Re: VB6 Halp required
First of all, go through our Database FAQ section to learn about ADO
-
Re: VB6 Halp required
Thread moved to 'Database Development' forum (the 'VB6' forum is only meant for questions which don't fit in more specific forums)