code to change form recordsource

  • Thread starter ryan.fitzpatrick3
  • Start date
R

ryan.fitzpatrick3

I would like to change the form's record source, but I get an error on
this code

Private Sub cboxYear_Click()
Dim LResponse As Integer
LResponse = MsgBox("Do you want to sum up the Year?", vbYesNo,
"Yes?")
If LResponse = vbYes Then
Me!frmAlumCans!RecordSource = "4QryAdageVolumeSpendYearsum"
End If
End Sub

It gives me error #2465 saying access can't find field referred in
expression, what does this mean?
 
D

DStegon via AccessMonster.com

you posted twice so I am copying from the otehr post... you should read that
post because another member made another good point

how about try this...

This assumes that cboxYear is a command button on the form in which this
routine is part of the module.

Private Sub cboxYear_Click()

if MsgBox("Do you want to sum up the Year?", vbYesNo,
"Yes?") = vbYes then
Me.RecordSource = "4QryAdageVolumeSpendYearsum"
End If

End Sub

much cleaner and easier to read and you are not testing the value of an int
but instead the boolean value of your msgbox response.
 
Top