Hi All,
I have a macro that basically checks for certain values in a textbox on the form and based on that hides or displays a button. It works very well as a macro, but then I used Access' facility to convert from Macro to VBA, it generated the code and when I replaced the macro with the corresponding function name, it gives me an error, which I cant seem to figure out. Below I am attaching both the macro and converted VBA code.
Macro Code:
Condition 1: ([cboLastRevd].[Value]<>[txtTruncRev].[Value]) And ([cboLastRevd] Is Not Null) And ([txtTruncRev] Is Not Null)
Action 1: Set Value ([cmdChangeRev].[Visible] = True)
Condition 2: ([cboLastRevd] Is Null) Or ([cboLastRevd]=[txtTruncRev])
Action 2: Set Value ([cmdChangeRev].[Visible] = False)
VBA Code:
Function mcrRevButtonVisible()
On Error GoTo mcrRevButtonVisible_Err
With CodeContextObject
If (Eval("([cboLastRevd].[Value]<>[txtTruncRev].[Value]) And ([cboLastRevd] Is Not Null) And ([txtTruncRev] Is Not Null)")) Then
.cmdChangeRev.Visible = True
End If
If (Eval("([cboLastRevd] Is Null) Or ([cboLastRevd]=[txtTruncRev])")) Then
.cmdChangeRev.Visible = False
End If
End With
mcrRevButtonVisible_Exit:
Exit Function
mcrRevButtonVisible_Err:
MsgBox Error$
Resume mcrRevButtonVisible_Exit
End Function
[cboLastRevd] & [txtTruncRev] are text boxes on the form and cmcChangeRev is the name of the button. Based on the values compared between the two text boxes, the button will either be visible or hidden. This macro is placed in the OnCurrent event of the form. I am using Access 2002 version. The error that I get is "MS Access cant find the name 'cboLastRevd' you entered in the expression". I am having similar problems with other macros/VBA code too, but I guess once I figure it out here, that should be able to solve the other ones too. Also, at some places the code does not generate the "With CodeContextObject" statement too. I cant seem to figure it out.
Thanks to all in advance for all your time and efforts.
Regards:
Prathmesh
I have a macro that basically checks for certain values in a textbox on the form and based on that hides or displays a button. It works very well as a macro, but then I used Access' facility to convert from Macro to VBA, it generated the code and when I replaced the macro with the corresponding function name, it gives me an error, which I cant seem to figure out. Below I am attaching both the macro and converted VBA code.
Macro Code:
Condition 1: ([cboLastRevd].[Value]<>[txtTruncRev].[Value]) And ([cboLastRevd] Is Not Null) And ([txtTruncRev] Is Not Null)
Action 1: Set Value ([cmdChangeRev].[Visible] = True)
Condition 2: ([cboLastRevd] Is Null) Or ([cboLastRevd]=[txtTruncRev])
Action 2: Set Value ([cmdChangeRev].[Visible] = False)
VBA Code:
Function mcrRevButtonVisible()
On Error GoTo mcrRevButtonVisible_Err
With CodeContextObject
If (Eval("([cboLastRevd].[Value]<>[txtTruncRev].[Value]) And ([cboLastRevd] Is Not Null) And ([txtTruncRev] Is Not Null)")) Then
.cmdChangeRev.Visible = True
End If
If (Eval("([cboLastRevd] Is Null) Or ([cboLastRevd]=[txtTruncRev])")) Then
.cmdChangeRev.Visible = False
End If
End With
mcrRevButtonVisible_Exit:
Exit Function
mcrRevButtonVisible_Err:
MsgBox Error$
Resume mcrRevButtonVisible_Exit
End Function
[cboLastRevd] & [txtTruncRev] are text boxes on the form and cmcChangeRev is the name of the button. Based on the values compared between the two text boxes, the button will either be visible or hidden. This macro is placed in the OnCurrent event of the form. I am using Access 2002 version. The error that I get is "MS Access cant find the name 'cboLastRevd' you entered in the expression". I am having similar problems with other macros/VBA code too, but I guess once I figure it out here, that should be able to solve the other ones too. Also, at some places the code does not generate the "With CodeContextObject" statement too. I cant seem to figure it out.
Thanks to all in advance for all your time and efforts.
Regards:
Prathmesh