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

Macro to VBA code

Status
Not open for further replies.

Prathmesh

Programmer
Oct 22, 2003
21
AU
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
 
Prathmesh

Sometimes it is easier to look at the functional requirements and re-do the code. Your new code will be much easier to read, and in "your style".

Richard
 
I agree with you, Willir and that is what I did. I wrote a custom function and then called it in the On Current event property of the form and it worked. Tks for your input. Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top