Macro Works, How do I write the Code

georget

Registered User.
Local time
Today, 15:27
Joined
Jul 17, 2002
Messages
31
Easy Questions?

I created a button that runs a Macro to do the following:

1. OpenForm (Form Name: Business)
2. ApplyFilter (Where Condition: [Business]![City]="Columbus")

It works fine, BUT I want to get away from Macros and write the code. So I assume I write the code using the On Load event (also tried After Update event). But the following didn't work (result was no records):

-----------------------------------------------------------------------

Private Sub Form_Load()

DoCmd.ApplyFilter , Forms![Business]![City] = "Columbus"

End Sub

-------------------------------------------------------------------------

But there are records because the Macro works.

What code does the MACRO write?

I know there are some great minds in this forum
...please help!



:D
 
In the Tools menu under Macro you can find an item called Convert Macros to Visual Basic. In the property tab of your button select the Event register and scroll down to the On Click event. Make sure the the contents is [Event Procedure]. Then click on the right side of the item on the ellipsis .... The Visual Basic editor will open. There you can paste the formerly converted code without the first and last row. After that you can delete the converted function.

Good luck.
 
Use the Access wizard to create a new button. You will be stepped through what you want to do... goto next record, previous record, new record, etc. Select form operations and the open form. On clicking next you should be asked if you want to show all records or go to a specific record. Once created you can study the code to get an idea of how it works.
HTH
Dave

PS This is the code the wizard created on one of my buttons:

Private Sub OpenProcedures_Click()
On Error GoTo Err_OpenProcedures_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Procedures"

stLinkCriteria = "[IDMain]=" & Me![IDMain]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_OpenProcedures_Click:
Exit Sub

Err_OpenProcedures_Click:
MsgBox Err.Description, , "ASSETSonTRACK"
Resume Exit_OpenProcedures_Click

End Sub

As you can see the criteria for the 'Goto' bit is governed by the field IDMain.
Dave
 

Users who are viewing this thread

Back
Top Bottom