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

Here is my code (Im getting the err

Status
Not open for further replies.

cppiston

Programmer
Feb 27, 2002
23
0
0
US
Here is my code (Im getting the error: Run-time error '3061':
Too few parameters. Expected 1. "

Private Sub txtGagePoint_Click()
On Error GoTo GagePoint_Enter
Dim db As Database
Dim qry As QueryDef
Dim rst As Recordset
Dim stDocName As String

DoCmd.SetWarnings False

stDocName = "qry_GagePoint"
DoCmd.OpenQuery stDocName, acNormal, acEdit

DoCmd.SetWarnings True

Set db = CurrentDb

Set qry = db.CreateQueryDef("", _
"Select GagePoint from `tbl_tmpGagePoint`" _
& "Where CamProfile = " & Text89)
Set rst = qry.OpenRecordset()

txtGagePoint = rst!GagePoint
Text89 = rst!CamProfile

Exit_GagePoint_Enter:
Exit Sub

Err_GagePoint_Enter:
MsgBox Err.Description
Resume Exit_GagePoint_Enter
 
Your sql's a bit tangled up. You need a space before WHERE. You probably don't want single quotes around the name of the table. And you will need them for the parameter you're passing in, if it's text (though leave that part alone if text89 holds a numeric value). And you should disambiguate your reference to that control. Here's how I'd rewrite it (assuming the control holds text):

Set qry = db.CreateQueryDef("", _
"Select GagePoint from tbl_tmpGagePoint" _
& " Where CamProfile = '" & Text89 & "'")

Oh, and look into help for how to use recordsets. It looks like you've got a couple of methods stepping on each others' toes. It's hard to tell exactly what you're trying to do, but I would think you'd want to do something more like this:
Private Sub txtGagePoint_Click()
On Error GoTo GagePoint_Enter
Dim db As Database
Dim rst As Recordset
Dim strSql As String

Set db = CurrentDb

strSql = "Select GagePoint FROM tbl_tmpGagePoint" _
& " Where CamProfile = '" & Text89 & "'"
Set rst = db.OpenRecordset(strSql, dbOpenSnapshot)

Me!txtGagePoint = rst!GagePoint

rst.Close
Set rst = Nothing
db.Close
Set db = Nothing

Exit_GagePoint_Enter:
Exit Sub

Err_GagePoint_Enter:
MsgBox err.Description
Resume Exit_GagePoint_Enter
End Sub

I left a bunch of stuff out because I couldn't tell what it was doing. Unless that query was a recordset, it wasn't really doing much for you. And you were setting text89 to itself.

If you explain more of what you're trying to do, we'll get you closer to the real answer.

Jeremy

Jeremy ==
Jeremy Wallace
AlphaBet City Dataworks
Affordable Development, Professionally Done

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
i have a table Job Order Entry... On this table exists a Combo Box (text89 Which has the selection of CamProfiles). Also a text box (GagePoint).

I also have another table luCamProfiles.

I am trying to have GagePoint get its default data from the luCamProfile table according to the Cam Profile chosen.

Does that make sense?
 
Hey, It works great!!!! thanks so much...
 


On Error GoTo GagePoint_Enter

should be

On Error GoTo Err_GagePoint_Enter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top