Search button to search inside a split form (1 Viewer)

ZeidHaddad

Registered User.
Local time
Today, 07:51
Joined
Oct 29, 2019
Messages
44
Hello everyone!
So I’m trying to use the following code to search in a split form

Dim strsearch As String
Dim Task As String
'Check if a keyword entered or not
If IsNull(Me.txtsearch) Or Me.txtsearch = "" Then
MsgBox "Please type in your search keyword.", vbOKOnly, "Keyword Needed"
Me.txtsearch.BackColor = vbYellow
Me.txtsearch.SetFocus
Else
strsearch = Me.txtsearch.Value
Task = "SELECT * FROM Dokumentation WHERE ((Vertragsnummer Like ""*" & strsearch & "*""))"
Me.RecordSource = Task
Me.txtsearch.BackColor = vbWhite
End If

But its not working and i think the mistake is from “me.recordsource = Task”
 

June7

AWF VIP
Local time
Today, 06:51
Joined
Mar 9, 2014
Messages
5,425
That line looks fine to me.

What is error message? What line triggers error?
 

ZeidHaddad

Registered User.
Local time
Today, 07:51
Joined
Oct 29, 2019
Messages
44
The line “me.recordsource = Task”
Run-time error 3022
 

isladogs

MVP / VIP
Local time
Today, 14:51
Joined
Jan 14, 2017
Messages
18,186
Are you sure? Error 3022 is
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.

So where are you appending records into the table?
Try adding the line Debug.Print Task before the line that errors
 

ZeidHaddad

Registered User.
Local time
Today, 07:51
Joined
Oct 29, 2019
Messages
44
Well it didn’t work!
I’m only trying to create a search box where i press a button to search in the split form. Maybe there is an easier way to do this
 

June7

AWF VIP
Local time
Today, 06:51
Joined
Mar 9, 2014
Messages
5,425
If you want to provide db for analysis, follow instructions at bottom of my post.
 

jdraw

Super Moderator
Staff member
Local time
Today, 10:51
Joined
Jan 23, 2006
Messages
15,364
Well it didn’t work! doesn't help readers.

As was mentioned Error 3022 is related to a duplicate record key/index being saved/attempted.
I don't think you would get a 3022 on a Select/Read statement.

For readers to offer focused responses, you'll have to provide more specific info.
Try screen captures of error messages and/or some debug.print statements to verify variable contents as you work through your code.
Good luck with your project.
 

Users who are viewing this thread

Top Bottom