Repost: How to dynamically change field data source on a form (1 Viewer)

Christine Pearc

Christine
Local time
Today, 02:29
Joined
May 13, 2004
Messages
111
I don't know if it is against "the rules" to repost, but I haven't received a response to my question posted yesterday (11-Oct) and need help asap.

I would like to create a button on FormA which will open FormB. Easy enough. However, I want the data source for the (single) field on FormB to vary depending on the field variable I set in FormA. Can someone tell me how to to do this? Here's the code in FormA that I have thus far:

Private Sub cmdZoom_Click()

Dim mZoomField as string
mZoomField = me.Description
DoCmd.OpenForm "frm Zoom", , , stLinkCriteria = "[CARNum]=" & Me![CARNum]

End Sub

Rich responded to my original request for help, suggesting I use the built-in command for ZoomBox. This isn't acceptable since the routine displays a formatting dialog (not needed because the field is a Stephen Leban's RTF control with its own formatting, and beside the ZoomBox screen is too small.

Any takers on this question?

Thanks,
Christine
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 02:29
Joined
Jul 9, 2003
Messages
16,280
From reading this post, I get the impression that you could achieve what you want by having your form and control unbound and then fill the controls with the data with a function via an SQL statement.

This may offer you a solution, but without knowing more about what you are trying to do I don't know!
 

Brianwarnock

Retired
Local time
Today, 02:29
Joined
Jun 2, 2003
Messages
12,701
Since you can set RecordSource and ControlSource via VBA then with some research and abit of trial and error you should be able to achieve what you want to do.

Brian
 

Brianwarnock

Retired
Local time
Today, 02:29
Joined
Jun 2, 2003
Messages
12,701
An idle hour had me playing and if the different record sources have the same named primary key fields its not difficult, however trying to be more general has had me going round in circles until I dissappeared up.. decided to go for walk

Brian
 

Brianwarnock

Retired
Local time
Today, 02:29
Joined
Jun 2, 2003
Messages
12,701
The walk cleared my head . I'm not saying this is the best way to do it but it works well on my 3 small tables and several fields it did.

In a module define the following Public constants

Code:
Public strConSource As String
Public strRecSource As String
Public lngRecordnumber As Long

For the fields you want to zoom place the code below in the event to activate the zoom. In the sample the control name was fldmemo

Code:
Private Sub fldmemo_Click()
strRecSource = Me.RecordSource
strConSource = Me.ActiveControl.name
lngRecordnumber = Me.CurrentRecord

DoCmd.OpenForm "frmzoom"
End Sub

In the, preferably, double click event of the textbox to view the zoomed data place the following, don't use the click event as it drives you mad as you try to edit :D
Text0 was of course the name of the text control on my frmzoom

Code:
Private Sub Text0_DblClick(Cancel As Integer)
Me.RecordSource = strRecSource
Me!Text0.ControlSource = strConSource
DoCmd.GoToRecord acDataForm, "frmzoom", acGoTo, lngRecordnumber
End Sub

Hope it helps

Brian
 

Brianwarnock

Retired
Local time
Today, 02:29
Joined
Jun 2, 2003
Messages
12,701
Better still olace the last code in frmzoom 's loadevent

Brian
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 02:29
Joined
Jul 9, 2003
Messages
16,280
You may be able to make use of this example......
 

Attachments

  • OpenAfromBChangeTxtSource.zip
    52.5 KB · Views: 162

Christine Pearc

Christine
Local time
Today, 02:29
Joined
May 13, 2004
Messages
111
Uncle Gizmo and Brianwarnock - Yes, yes, yes!! Thank you very much. It would have taken me ages longe to figure it out. The sample goes beyond what I'd originally wanted (ref to single table), but what you've provided offers *loads* of possibilities for future projects!

Ta very much,
Christine
 

Users who are viewing this thread

Top Bottom