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

problem with code behind a button

Status
Not open for further replies.

cochise

Technical User
Joined
Mar 27, 2001
Messages
171
Location
US

Can anyone see what maybe wrong with how I setup this button? It doesn't seem to work.

Private Sub cmdFindRecord_Click()
Dim datDate As Date
Dim strTechNum As String

datDate = Me.txtDate
strTechNum = Me.cmbTechNum

Forms("frmDailyPerformanceSummary").RecordSource = _
"SELECT tblDP.TechNum,tblDP.Date, " & _
"tblDP.HoursWorked, t
"FROM tblDP " & _
"WHERE tblDP.TechNum = " & strTechNum & _
"AND tblDailyPerformance.Date = " & datDate

End Sub
 
"WHERE tblDP.TechNum ='" & strTechNum & "' & _
"AND tblDailyPerformance.Date = #" & datDate & "#"

Try this.
Paul
 
Generally, it's not a good idea to change a form's Record Source except at Open time. You should use the form's Filter and FilterOn properties to select records from the form's underlying Recordset. For example:
Code:
Forms("frmDailyPerformanceSummary").Filter = _
  "[TechNum] = " & strTechNum & _
  "AND [Date] = " & datDate
Forms("frmDailyPerformanceSummary").FilterOn = True
Also, a form has only one underlying record source. Your sample code is selecting records based on two tables, tblDP and tblDailyPerformance.

 
Jfischer- Thanks,

I tried using your code, however, I got the following error:

Run-time error 3022

The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship.....

Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top