How chceck if record i want to add isn't already exists?

the_wickedman

New member
Local time
Today, 08:27
Joined
Aug 12, 2006
Messages
3
In my database, (under Access 2003 (VB6)) I have table "tblPhoto" in which I keep path(s) to my picture(s) like CurrentDatabasePath + "Zdjecia" + .txtPhoto

Count "Photo" looks like:

13.JPG
123.BMP
Ustronie\Zachód.JPG

When I add new pic for ex. 345.JPG to my database (table) I want to chceck if 345.JPG doesn't already exist (in column "Photo") but without showing him -> only get value TRUE/FALSE (it is/it isn't). How search in the table (column Photo)?

I found this (but in VB6 I have problem with SqlConnection/SqlCommand type)
Private Sub znajdz()
Dim cnn As New SqlConnection("Database = Nazwa; Integrated security = SSPI")
Dim cmd As New SqlCommand()
Dim ile As Integer
cmd.Connection = cnn
cmd.CommandText = "select count(*) from Photo where Photo like 'nazwa'"
cnn.Open()
ile = cmd.ExecuteNonQuery()
cnn.Close()
If (ile > -1) Then
MsgBox"Record exists"
Else
MsgBox"Record not found"
End If
End Sub
 
Probably the easiest way is to use either DLookup or DCount. Search the forum and your help file for examples (keywords: DLookup, DCount). If you get stuck with the syntax, post back with your code and I'm sure someone can help.

Regards,
Tim
 
Thanks, I'll try it soon

Regards,
 

Users who are viewing this thread

Back
Top Bottom