Marchese Il Chihuahua
Marchese Il Chihuahua

Reputation: 1129

Using code to identify which form is currently open

I am creating a database with many forms within it where frequently i require a "zoom in box" to open a field on a record and allow the user to enter long lines of text into a 'memo' field. At the moment due to my limited vba programming knowledge, I am forced to create a new (and identical) zoom in form for each field where I would like to zoom in on. I am wondering if it is possible to NOT have to create a new form each time i want to do this but to only have one standard 'zoom-in' form which knows which table/field is being accessed.

Upvotes: 0

Views: 146

Answers (1)

Sham Yemul
Sham Yemul

Reputation: 463

I assume you have same table and just wanting to change field name , in case the table name and field also changed, we can write the logic for the same with sample code below.

When opening the form you need to know which field needs to be used. There is facility in Microsoft Access VBA when opening a form, we can pass OpenArgs. This OpenArgs can be used as a way to understand which field to set the zoom form.

'Code when the zoom button clicked
DoCmd.OpenForm "frmZoom", , , , , , "memoField1"

Write code for each of the desired button, so you can pass which field to use for the zoom form.

The open event of Zoom form will have following code

'Check which field we need to set for the memo field
Select Case Me.OpenArgs 
Case "memoField1"
    Me.tbMemoField1.ControlSource="memoField1"
Case "memoField2"
    Me.tbMemoField2.ControlSource="memoField2"
End Select

Replace the field names and control names as per your needs above.

Upvotes: 1

Related Questions