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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help with this code

Status
Not open for further replies.

Travis33

Programmer
Nov 20, 2000
31
US
I HAVE THIS CODE BELOW THAT i AM TRYING TO HAVE MY FORM WHEN I ENTER IN NUMBERS INTO A COMBO BOX SCROLL THROUGH THE RECORDS THAT MATCH PART OR ALL OF THE STRING.

**********************************************************
Dim db As database, rst As Recordset, strsql As String
Set db = CurrentDb
Str = "select * from [mtusparts01 query]= " & Me.[partnumber] & " * "
Set rst = db.openrecordset(strsql)
If rst.RecordCount >= 1 Then
Me.RecordSource = strsql
Else
Exit Sub
End If
rst.Close
Set db = Nothing
***********************************************************

when I try to compile the code it gives me an error on
me.[partnumber]
it tells me "Argument Not Optional"
How do I fix this so my code will run
Thank You,
Travis
 
I beleive that you need a "fully qualified" reference. "Me" can only refer to an active form/report. When your code is inprocess (e.g. PART of the form or report, it cam only refer to controls on the form/report. Otherwise it is "illegal"

MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Create a variable for the form's field (Me.partnumber) and use it in your SQL statement instead.

varPart = me.partnumber

something like that...

Mary :eek:)
 
if you are attempting to build a string then the problem is in your statement
Str = "select * from [mtusparts01 query]= " & Me.[partnumber] & " * "

should read
strsql = "select * from [mtuspart01 query] where [field1] = " me.[part number] " *"

the field1 should be the field in msuspart01 query you want to match and me.[partnumber] should be the name of the field on your form you are doing the look up from
 
Just read an earlier post and noted what you are attempting to do. I see both persons who responded suggested you use a combo box and set the rowsource to include the description. I too agree with what they suggest. Is there a reason you can't do it that way?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top