Transferring a Macro into Visual Basic code.

gigifarrow
gigifarrow used Ask the Experts™
on
I have a macro that is used after update.


I need to transfer that into Visual basic code Because I need to add more code that is in visual basic.

This is the Macro I need Transfered into visual basic:
After_Update_MOD
Action                                          Argument
Set Value                [Forms]![frmVehicleMOD]![Part Number], DLookUp                   ("[PartNumber]","[tblMODKits]","[MOD Kit]= Forms![frmVehicleMOD]![MOD]")

Set Value                     [Forms]![frmVehicleMOD]![MWO], DLookUp("[MWO]","[tblMODKits]","[MOD Kit]= Forms![frmVehicleMOD]![MOD]")



Once the code does this I am adding the following code which is based on what the output of the Macro below displays:

If Me.MOD = "BFCS" Then
MsgBox "Please Enter Fuel Cell Information." Then

DoCmd.OpenForm "frmfuelCellInfo"

If Me.MOD = "AFES CEP Protective  Switch Guard" Then
MsgBox "Please Enter Fuel Cell Information."

DoCmd.OpenForm "frmfuelCellInfo"


End If
End If

End Sub
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
What version of access are you using?
You didn't mentioned Access version. In Access 2010 you have ribbon command:
convert macrossource:
http://blogs.office.com/b/microsoft-access/archive/2009/07/28/meet-the-access-2010-macro-designer.aspx
NorieAnalyst Assistant
Commented:
Access will convert a macro to code for you.

Just open the macro in design view and select Convert Macros to Visual Basic.

That's on the Macro Tools Design tab in Access 2010, I think it was on the Database Tools tab in 2007 and could be accessed via a menu in earlier versions.
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

consultant
Commented:
MsgBox "Please Enter Fuel Cell Information." Then - drop Then - to avooid a syntax error.

If I were your user I would rebel against having to OK a message box. Why not just open the form - you can always put a label in the form saying Please Enter Fuel Cell Information.

You can simplify the code :
If Me.Mod = "BFCS" Or Me.Mod = "AFES CEP Protective  Switch Guard" Then
  DoCmd.OpenForm "frmfuelCellInfo"
End If

Open in new window

Author

Commented:
How do you convert a macro to visual basic in 2007?
Commented:
Select the macro, then under the 'DatabaseTools' tab choose 'Convert Macro into Visual Basic'.
NorieAnalyst Assistant

Commented:
Like I said in my earlier post in Access 2007 Convert Macro to VBA... is on the Database Tools tab.

Commented:
Yes, its exactly like what imnorrie said except that you don't open the macro in design view, just highlight the macro in the navigation pane.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial