Solved adding variables to sql

ClaraBarton

Registered User.
Local time
Today, 07:29
Joined
Oct 14, 2019
Messages
699
I cannot get the variable to return a value and
I can't think of anything else to try:
Code:
        GOAL: AuthorID = 2065
txtID = DLookup("[IDField]", "[tblLists]", strCrit)
Returns:   AuthorID
strWhere = "txtID = " & Me.lstEditList.Value
        txtID = 1932

strWhere = " & txtID & " = Me.lstEditList.Value
        False

strWhere = "txtID = Me.lstEditList.Value"
        txtID = Me.lstEditList.Value
    
strWhere = " & (txtID) & = " & Me.lstEditList.Value
        & (txtID) & = 2068

strWhere = """ & (txtID) & = """ & Me.lstEditList.Value
        " & (txtID) & = "2068

strWhere = "(txtID) = " & Me.lstEditList.Value
        (txtID) = 2068
 
totally confused by your description - your dlookup is returning IDfield whereas you apparently want AuthorID. Your criteria is a string called strCrit but you appear to populating a string called strWhere from that dlookup and that doesn't look right either
 
the strCrit is right; it is returning AuthorID. I just want to get that into the strWhere. I've done it all those times and the line under is what I get. My syntax is wrong each time. My goal is the first line.
 
I cracked it. Here's the lesson:

var1 = "stuff inside quote marks is called a literal."
var2 = "to use whats in a variable you can't put the variable in quote marks."

var1 and var2 are variable and I set them equal to literals. Now let's use their names and also what is inside them:

var3 = "The instances of var1 in this sentence are inside quote marks so the value inside var1 will not be used."
var4 = "As you know, " & var1 & " So, " & var2 & " You must end the quote marks and use an ampersands to add it like this."
 
yes... yes... yes... No! I don't get it! How do I write the strWhere?
 
Do you want the literal value 'txtID' to appear in strWhere or the value inside it?

That's rhetorical
 
I'm missing something here... I've used variables in the middle and at the end but I can't figure how to start the string...
 
strWhere = txtID & " = " & Me.lstEditList.Value
I got it! i got it! Thank you so much!
Well, you got it!
 

Users who are viewing this thread

Back
Top Bottom