Select......Like

G

Guest

Hi, I want to build a Select sentence with a LIKE "PartOrACode*" option but I
dont know where to put the "*", the key field is txt and the sentence I have
is :

Sql = "SELECT tblComputers.AssetTag, tblComputers.ManufacturerID,
tblComputers.DateReceived, tblComputers.PurchasePrice, tblComputers.Warranty,
tblComputers.EmployeeID " & _
"FROM tblComputers WHERE AssetTag LIKE """ &
[Forms]![frmComputers]![Text12] & """"

Forms!frmComputers.RecordSource = Sql

Thanks
 
D

Dirk Goldgar

In
Orlando said:
Hi, I want to build a Select sentence with a LIKE "PartOrACode*"
option but I dont know where to put the "*", the key field is txt and
the sentence I have is :

Sql = "SELECT tblComputers.AssetTag, tblComputers.ManufacturerID,
tblComputers.DateReceived, tblComputers.PurchasePrice,
tblComputers.Warranty, tblComputers.EmployeeID " & _
"FROM tblComputers WHERE AssetTag LIKE """ &
[Forms]![frmComputers]![Text12] & """"

Forms!frmComputers.RecordSource = Sql

Try this:

Sql = _
"SELECT " & _
"AssetTag, ManufacturerID, DateReceived, " & _
"PurchasePrice, Warranty, EmployeeID " & _
"FROM tblComputers " & _
"WHERE " & _
"AssetTag LIKE """ & [Forms]![frmComputers]![Text12] & "*"""

Although personally, I prefer to use Chr(34) instead of those long
strings of doubled-up quotes:

"WHERE AssetTag LIKE " & _
Chr(34) & _
[Forms]![frmComputers]![Text12] & "*" & _
Chr(34)
 
G

Guest

Try

Sql = "SELECT tblComputers.AssetTag, tblComputers.ManufacturerID,
tblComputers.DateReceived, tblComputers.PurchasePrice, tblComputers.Warranty,
tblComputers.EmployeeID " & _
"FROM tblComputers WHERE AssetTag LIKE '" & [Forms]![frmComputers]![Text12]
& "*'"

Forms!frmComputers.RecordSource = Sql
 
D

Dirk Goldgar

In
Ofer Cohen said:
Try

Sql = "SELECT tblComputers.AssetTag, tblComputers.ManufacturerID,
tblComputers.DateReceived, tblComputers.PurchasePrice,
tblComputers.Warranty, tblComputers.EmployeeID " & _
"FROM tblComputers WHERE AssetTag LIKE '" &
[Forms]![frmComputers]![Text12] & "*'"

Using a single-quote (') as the text delimiter in the SQL string
simplifies things a lot, provided you are confident that the literal
value being embedded doesn't contain that character. I tend to use
double-quotes (") habitually, as they are much less common.
 
G

Guest

Thanks, the routine works, but let say I place Data entry to yes, because I
dont want to se the first register in screen when I fill the text box with
the code and and click in the command button that have the code you show me,
the Select doesn't works, but if I move Data Entry to NO (It shows the first
register) work perfect.

Any Ideas how to fix this problem?

Thanks

Ofer Cohen said:
Try

Sql = "SELECT tblComputers.AssetTag, tblComputers.ManufacturerID,
tblComputers.DateReceived, tblComputers.PurchasePrice, tblComputers.Warranty,
tblComputers.EmployeeID " & _
"FROM tblComputers WHERE AssetTag LIKE '" & [Forms]![frmComputers]![Text12]
& "*'"

Forms!frmComputers.RecordSource = Sql


--
Good Luck
BS"D


Orlando said:
Hi, I want to build a Select sentence with a LIKE "PartOrACode*" option but I
dont know where to put the "*", the key field is txt and the sentence I have
is :

Sql = "SELECT tblComputers.AssetTag, tblComputers.ManufacturerID,
tblComputers.DateReceived, tblComputers.PurchasePrice, tblComputers.Warranty,
tblComputers.EmployeeID " & _
"FROM tblComputers WHERE AssetTag LIKE """ &
[Forms]![frmComputers]![Text12] & """"

Forms!frmComputers.RecordSource = Sql

Thanks
 
G

Guest

Leave the form DataEntry in false, but set the original RecordSource of the
form with a filter that return no records.

Select * From tblComputers WHERE AssetTag Is Null

That way no records will be displayed until you set the record sorce again
with your code

--
Good Luck
BS"D


Orlando said:
Thanks, the routine works, but let say I place Data entry to yes, because I
dont want to se the first register in screen when I fill the text box with
the code and and click in the command button that have the code you show me,
the Select doesn't works, but if I move Data Entry to NO (It shows the first
register) work perfect.

Any Ideas how to fix this problem?

Thanks

Ofer Cohen said:
Try

Sql = "SELECT tblComputers.AssetTag, tblComputers.ManufacturerID,
tblComputers.DateReceived, tblComputers.PurchasePrice, tblComputers.Warranty,
tblComputers.EmployeeID " & _
"FROM tblComputers WHERE AssetTag LIKE '" & [Forms]![frmComputers]![Text12]
& "*'"

Forms!frmComputers.RecordSource = Sql


--
Good Luck
BS"D


Orlando said:
Hi, I want to build a Select sentence with a LIKE "PartOrACode*" option but I
dont know where to put the "*", the key field is txt and the sentence I have
is :

Sql = "SELECT tblComputers.AssetTag, tblComputers.ManufacturerID,
tblComputers.DateReceived, tblComputers.PurchasePrice, tblComputers.Warranty,
tblComputers.EmployeeID " & _
"FROM tblComputers WHERE AssetTag LIKE """ &
[Forms]![frmComputers]![Text12] & """"

Forms!frmComputers.RecordSource = Sql

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help with a SELECT 3
Confusion between two routines 1
Creating a date calculation with a text form field 2
Next month 4
Filtering subforms 1
Access MS access forms list box problems 1
Problem with Select 2
MSI script 1

Top