Hi i am new to vb6, i am trying to generate reports in word application, that all works, but my problem is i have one database containing 6 fields, i used ADODC to connect to db and i can save records, my fields are
1. Report number
2. Name
3. Address line1
4. Address line2
5. Sample number
6. Sample received on
My problem is i defined report number as primary key.
when user try to store report number it checks whether that report exists or not, if it exists it pop up's the msg and allow to enter different rep num for that my code is
Private Sub cmdsave_Click()
On Error GoTo 10
10
Dim a As ErrorValueEnum
If Err.Number = "-2147467259" Then
a = Err.Number
MsgBox (a)
MsgBox ("This Report Number is already exists, enter different report number")
Txtrepnum.SetFocus
Txtrepnum.Text = ""
Exit Sub
End If
Close 10
Adodc1.Recordset.Update
cmdclear.Enabled = True
cmdsave.Enabled = False
cmdcancel.Enabled = False
End Sub
now some records are already there in db, i want to retrieve them by using primary key, i have command as retrieve, when i enter report number(primary key), it should get corresponding sample number and other details, but i am failed to that, when i enter first rep num it will retrieve the correct value but when i give 2nd, 3rd, report number it's retrieving only 1st sample number only not corresponding to that means cursor is not getting the corresponding values from db, i dont knw how to solve this problem, plz help me, i have to submit this by tomorow morning plzzzzz.
my code to retrieve data from db is,
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim str As String
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
rs.CursorType = adOpenDynamic
str = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\Documents and Settings\Administrator\Desktop\original Provisional Report System\provrepdetails.mdb"
cn.Open str
rs.Open "provrepdetails", cn
Trim (Txtrepnum)
Trim (rs("name"))
Trim (rs("sample number"))
str = "select Sample number, name from provrepdetails where rs.Report Number = " & " '" & Txtrepnum & "'"
MsgBox (rs("name"))
MsgBox (rs("sample number"))
MsgBox (rs("sample number"))
MsgBox (str)
'End If
'Do While Not rs.EOF
txtname.Text = rs("name")
txtsamnum.Text = rs("sample number")
rs.MoveFirst
'Trim (Txtrepnum)
'Trim (txtsamnum)
'Loop
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
cmdclear.Enabled = True
cmdsave.Enabled = False
cmdcancel.Enabled = False
End Sub
plz reply me as soon as possible.