Find record by text data type rather than number data type

Nic

Registered User.
Local time
Today, 20:45
Joined
Jan 15, 2012
Messages
47
Hi,
Please excuse my amateur approach here:

I have a table with records in it called 'sheet1'
I then have a form, with an unbound text box on it, with the below code behind the after update function. (this is just the start of the code).

So, if in my table my 'Barcode No' field is formatted to a number data type, this code works fine; but i need to format my 'Barcode No' field in my table to text data type; but then i get a data mismatch error appear. How can i make this work with text instead of number?


Private Sub ScanBarcode_AfterUpdate()

Me.ItemCode = ""
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("Sheet1", dbOpenDynaset)
With rst
.FindFirst "[Barcode No] = " & Me.ScanBarcode

After this code there is a whole load of additional code, to populate other objects on my form from the record that is found from the above.

I have been pulling my hair out with this for days, so any help would be greatly appreciated.

Many thanks
 
change to:

.FindFirst "[Barcode No] = " & Chr(34) & Me.ScanBarcode & Chr(34)
 
That is brilliant! Thanks - i never realised it would be so simple.

One further thing if you dont mind:

Further down in my code, there is a bit that applies a filter to a subform; with the above solution you have provided, my main form works fine, and my search works, but then i get a data type mismatch with this piece of code:

If Forms!Form5.Check40 = True Then
Forms!Form5![Sheet1 Subform].Form.Filter = "[SKU Barcode No]=" & Forms!Form5![Sheet1 Subform].Form.Text27
Forms!Form5![Sheet1 Subform].Form.FilterOn = True

The bottom line of this code is highlighted yellow.

Where would i look to correct this? Or can i just adjust this piece of code?

Thanks so much for your help!
 
see what i added on post#2, try to do it by yourself.
 
head scratching over; and solved it! Thanks for your help! :-)
 

Users who are viewing this thread

Back
Top Bottom