Adding/Searching DataBase

Zero_Hour
10-18-2000, 03:16 PM
Hello, I'm having a little trouble getting the database to add and search through. Was wandering if anyone has any idea's on how to get this code working right. And what I'm missing. I have adoc, and the data environment on. The database will load, and I can scroll at the data, and delete data, but not add and search/find. I'm encluding some of the code.
Thank you for any help.

Private Sub Command1_Click()
prompt$ = "To Enter a New Record click OK"
reply = MsgBox(prompt$, vbOKCancel, "Add New Record")
If reply = vbOK Then ' If the user clicks OK
txtText1.SetFocus 'move cursor to Text1 box
DataEnvironment1.rsCommand1.Recordset.AddNew ' and get new record
End If
End Sub

Private Sub Command2_Click()
prompt$ = "Enter the Trouble Ticket Number to start serch"
'get string to be used in the Trouble Ticket field serch
SearchStr$ = InputBox(prompt$, "Ticket Search")
DataEnvironment1.rsCommand1.Index = "Trouble Ticket" 'use Trouble Ticket
DataEnvironment1.rsCommand1.Seek "=", SearchStr$ 'and search
If DataEnvironment1.rsCommand1.NoMatch Then 'if no match
DataEnvironment1.rsCommand1.Recordset.MoveFirst 'go to first record
End If
End Sub

crideout
10-25-2000, 01:52 PM
For the first problem you need a recorset.update to actually save the record that you add. If you just say recordset.addnew and assign values to the database with out the update command the database assumes that you've cancelled your changes. The same applies for recordset.edit.

As for the second problem I'm not to sure. But this is what I did for a search record in a recent project:

Private Sub cmdfind_Click()
Dim answer As Integer
Dim rst As Recordset
Dim nonrst As Recordset
Dim fldate As Date
Dim found As Boolean
found = False


fldate = fdate.Text
If custnum.Text <> "" Then
Set rst = dbaeroplan.OpenRecordset("select * from points where sent=0 and acct=" & Chr(34) & custnum.Text & Chr(34) & " and flt=" & Chr(34) & Fnum.Text & Chr(34), dbOpenDynaset)
While Not rst.EOF
If Format(rst!fdate, "DD/MM/YYYY") = fldate Then

Label4.Visible = True
Label5.Visible = True
Label6.Visible = True
depart.Caption = rst!oac
arrive.Caption = rst!dac
booking.Caption = rst!bcc
cmdDelete.Enabled = True
found = True
End If
rst.MoveNext
Wend
end sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum