form crashing on rst.findfirst

Kuhn

Registered User.
Local time
Today, 13:01
Joined
Oct 21, 2013
Messages
17
hello, I have a form with behind it a dataset (a linked table from another ACCESS DB).
On the form I have a button with an input box for a search function,
which show the searched record (based on a value CTR_ID from the table.
however this button crashes (90% of the time).
I have found where it crashes, it's on the findfirst part, here are some code snippits:

Code:
Dim rst As DAO.Recordset
Dim strCriteria, seek_Ctr As string
Set rst = Me.Recordset

strCriteria = "[CTR_ID] = '" & seek_ctr & "'"

rst.FindFirst (strCriteria)

an example of the value of strcriteria = [CTR_ID] = '000094591261'


it does not always crash, weirdly enough, but when it does I get the message 'access has stopped working.

For the future, I plan to change the search function, put it outside the form, and only open the form with a recordset with only concerned record (select * where [CTR_ID] = '000094591261') , but I really would like a solution for this, I can't seem to find the cause :(
 
You do not set the seek_Ctr to anything.
The way you declare variables isn't correct, only seek_Ctr is declared as string, strCriteria is variant type.
Code:
Dim strCriteria, seek_Ctr As string
To declare both as string:
Code:
Dim strCriteria [B][COLOR=Red]As String[/COLOR][/B], seek_Ctr As string
 
ah sorry,I did put the 'as string' for each variable.
I did not put the whole code, just some snippits, because there is some other stuff going on as well. I did not write the original code to this form, just lucky to inherit this from someone...


seek_ctr is actually just a string with a function that adds leading zero's to the contract id the user put in the input box.

strseek = InputBox("Fill in the number of the contract " & Me.MAK.Form.type_ctr & " ? ", "Search Contract", vbOKCancel + vbQuestion)

seek_ctr = ts_zero(strseek, 15)
strCriteria = "[CTR_ID] = '" & seek_ctr & "'"

so ts_zero is a function that just adds leadings 0 until the total lenght of the string = 15 in this case (the way contracts are stored in the DB)
 
to be clear: CTR_ID is a short text column, the ID's can contain text.
 
Try using RecordsetClone:
Code:
Set rst = Me.RecordsetClone
Posting only some code snippits isn't the best way for others to find errors in code, (actually post the whole code, what is the code after FindFirst?). And don't type it in, but copy from the code source.
 
nvrmind I decided to ditch the old form and created a better one, works fine now.
this can be closed.
 

Users who are viewing this thread

Back
Top Bottom