Search code examples
vbams-access

Me!control_textbox.Requery Run-time error '438' Object doesn't support this property or method


I have been searching forums for hours and can't find a remedy for this error which I have not had any issues with in the past.

I have the below code which creates the job number. The text box holding the job number should then show the updated result but I have to click on the textbox control to show the update. So I added Me.JobNumber.Requery but then get the error Run-time error '438' Object doesn't support this property or method.

The only intellisense option that comes up when I start to write the line is .Value but that throws the same error. I've tried Me. and Me! and textbox with and without []. I have other fields within this code that update textbox controls and they all work great, just this one evades me.

If dCount("JobNumber", "tblDelivery", "JobNumber='" & Forms!fmJob.JobNumber + "-" + DeliveryType & "'") = 0 Then
If Me.JobNumber Like "*-*" Then
Me!JobNumber = Left(Forms!fmJob.[JobNumber], InStr(Forms!fmJob.[JobNumber], "-"))
Me!JobNumber = Forms!fmJob.JobNumber + DeliveryType
Me![JobNumber].Requery
Else
Me!JobNumber = Forms!fmJob.JobNumber + "-" + DeliveryType
Me![JobNumber].Requery

End If

Solution

  • Your code shows using bang (!) in the Requery. That error will occur if textbox does not have same name as field, because then ! forces code to address the field since it does not find a control by that name. Fields cannot be requeried. Use . when referencing controls and ! when referencing fields. I always give data controls a name different from fields, such as tbxJobNum.

    There is no need to Requery a bound textbox anyway. It should immediately show new value and if record is not already in edit mode, this will cause it to be. If value does not show, then something else is wrong. Regardless, Requery is useless so remove Requery lines.

    Doesn't make sense to extract part of Forms!fmJob.JobNumber in one line then in next line, concatenate entire value. Perhaps you meant second line to be:

    Me!JobNumber = Me!JobNumber + DeliveryType

    Consider one line instead of two to build JobNumber:

    Me!JobNumber = Left(Forms!fmJob.JobNumber, InStr(Forms!fmJob.JobNumber, "-")) & DeliveryType