Search Form Using Combo box for linked form and subform (1 Viewer)

theinviter

Registered User.
Local time
Today, 09:44
Joined
Aug 14, 2014
Messages
240
Hi
i need a help;
i am having a form linked to subform.
so i want to make a new multiple search form to to filter and display the information base on my selection in dropbox.
i tried this:


Private Sub mlocation_AfterUpdate()

Dim my_ck As String
my_ck = " select * from [Dispensing 2] where ([Drug name]= " & Me.mlocation & " )"

Me.Dispensing__2_Subform.Form.RecordSource = my_ck
Me.Dispensing__2_Subform.Form.Requery


End Sub



but got this error message:
Syntax Error ( missing operation) in query expression ([Drug name]= " & Me.mlocation & " )"
then this field get highlighted yellow:
Me.Dispensing__2_Subform.Form.RecordSource = my_ck


so what is the solution please.
 

Attachments

  • EM test.zip
    1.6 MB · Views: 43

CJ_London

Super Moderator
Staff member
Local time
Today, 17:44
Joined
Feb 19, 2013
Messages
16,607
Drug Name implies the field is text. If it is the code needs to be


my_ck = " select * from [Dispensing 2] where ([Drug name]= '" & Me.mlocation & "' )"
 

theinviter

Registered User.
Local time
Today, 09:44
Joined
Aug 14, 2014
Messages
240
hi
done as you said :
my_ck = " select * from [Dispensing 2] where ([Drug Name]= '" & Me.mlocation & "' )"


got this error:

data type mismatch in criteria expression .
 

isladogs

MVP / VIP
Local time
Today, 17:44
Joined
Jan 14, 2017
Messages
18,216
There shouldn't be a space before the final bracket:

Code:
& "')"

Similarly no space before SELECT at start
Code:
my_ck = "select *

In fact you could omit the brackets completely:
Code:
my_ck = "select * from [Dispensing 2] where [Drug Name]= '" & Me.mlocation & "'"
 

CJ_London

Super Moderator
Staff member
Local time
Today, 17:44
Joined
Feb 19, 2013
Messages
16,607
the datatype mismatch error says you are trying to compare different datatypes. I only said change it if the values are text.

I do find it strange you are comparing a drug name with what appears to be a location value.

also, if you are using lookups in your table, that will add to the confusion
 

JHB

Have been here a while
Local time
Today, 18:44
Joined
Jun 17, 2012
Messages
7,732
As CJ_London mention, the problem is the Lookup field type you use for the "Drug Name" field.
Try the below.
Code:
my_ck = "select * from [Dispensing  2] where [Drug name]=" & Me.mlocation[B][COLOR=Red].Column(0)[/COLOR][/B]
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:44
Joined
May 7, 2009
Messages
19,237
if your mlocation combobox has two columns where column1=id or unique key, and column2 is the drug name, you use:

my_ck="select * from [Dispensing 2] where [Drug name]= '" & me.mlocation.Column(1) & "'"


if there is only one column showing drug name:

my_ck="select * from [Dispensing 2] where [Drug name]= '" & me.mlocation & "'"


remember that that if you set the Bound Column to 1, then these are same:

mlocation = mlocation.value = mlocation.column(0)
 

Users who are viewing this thread

Top Bottom