Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not a valid field name 2

Status
Not open for further replies.

fileman1

Technical User
Feb 7, 2013
152
GB
I am trying to see if a Keyword is in a record set, but getting an error 3070 not a valid field name.

I am trying to see if :
Code:
    Set rs2 = db.OpenRecordset("Keyword", dbOpenDynaset)
    rs2.FindFirst "ID1 = " & Me.ID1 & " AND Keyword = " & Me.Combo3.Text[code]
[/code]

ID1 is a primary key value, Keyword is a field in a table called Keyword. The combo provides the name of the Keyword to be found.


 
I would never have a field and table with the same name.
tblKeyword
Keyword
And keyword is a string needs single quotes

rs2.FindFirst "ID1 = " & Me.ID1 & " AND Keyword = '" & Me.Combo3.value & "'"

And doubt you want the text property of the combo
 
Boy was I pleased you came along! That's done it, thanks very much. And yes, I changed the fieldname
 
You may also change your code to:

Code:
Dim strFilter As String

strFilter = "ID1 = " & Me.ID1 & " AND Keyword = '" & Me.Combo3.value & "'"

Debug.Print strFilter

rs2.FindFirst strFilter

so you can see what your db gets

Have fun.

---- Andy
 
Thanks Andy, I think Chinese must be easier to learn than SQL
 
Not really, fileman1 :)

I have a tool (in VB6) to create pretty much all of my SQLs (with some exceptions of UNIONs etc.) I am sure you have the same in Access (query builder?). As far as ‘translating’ it to VB(A) code with all & “ “ & _ I created another tool that takes SQL like this:
[tt]
Select Field1, Field2
From SomeTable
Where Field1 = ‘ABCD’
And Field2 = #4/16/2013#
Order By Field2
[/tt]
And with one click gives me this:
[tt]
"Select Field1, Field2 " & vbNewLine _
& " From SomeTable " & vbNewLine _
& " Where Field1 = ‘ABCD’ " & vbNewLine _
& " And Field2 = #4/16/2013# " & vbNewLine _
& " Order By Field2"
[/tt]

Then I just replace hard coded values with my variables and I am done. :)

Have fun.

---- Andy
 
Very good. I used to have VB6 but took it off when VB.Net came out, as I refused to learn a completely new syntax. Thanks for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top