Change of data type

leighj

Registered User.
Local time
Today, 03:26
Joined
Apr 5, 2017
Messages
10
Hi All,

I'm using a multi-field search code, which I got from this forum

I've also inserted code so that when a record is selected in the search, i can click a button - and it the particular record found will carry into a new form.

Code:
Private Sub btnLoan_Click()
On Error GoTo Err_btnLoan_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmEquip_Issue"
    
    stLinkCriteria = "[txtBarcode]=" & Me![txtBarcode]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_btnLoan_Click:
    Exit Sub

Err_btnLoan_Click:
    MsgBox Err.Description
    Resume Exit_btnLoan_Click

End Sub

Basically... when I first set it up - one of the fields that I was searching on "txtBarcode" was only numbers. Now, the data that I need to enter contains letters and numbers.

Since changing the data type and inputting my new data, the button has broken. When I click it, I receive an Enter Parameter Value box...

Is there a solution for this?

Any help appreciated.

Cheers,
Leigh
 
Yes you need to add quotes to your criteria to delimit it as a string - change this line. They are single quotes added with double quotes.

Code:
 stLinkCriteria = "[txtBarcode]=[COLOR="red"]'[/COLOR]" & Me.[txtBarcode] & [COLOR="Red"]"'"[/COLOR]
 
This is the offending line:
Code:
stLinkCriteria = "[txtBarcode]=" & Me![txtBarcode]
Because it is text not a number, you need additional quotes:
Code:
stLinkCriteria = "[txtBarcode]='" & Me![txtBarcode] & "'"
That's a single quote ' before closing the main quotes " and the same in reverse after.
 
That's pretty neat - 2 identical answers a minute apart!

Your result would have been (e.g.) "[txtBarcode]=ABC"
The result would now be "[txtBarcode]='ABC'"
 

Users who are viewing this thread

Back
Top Bottom