Unorthodox Routing

macattack

Registered User.
Local time
Today, 05:03
Joined
Jan 5, 2013
Messages
35
I'm rather new to Access and I've been trying to get something to work and countless searches have provided nothing that I can use.

I'm trying to set buttons as numbers on one form and then checking another form to see if those buttons were pressed so it will set RecordSource.

Button Form:
DoCmd.OpenForm "LRU Data", acNormal, , , acFormAdd
intLRU = 1

Next Form:
If intLRU = 1 Then Me.RecordSource = AFT
Doesn't work.

I also tried using the button to set a hidden textbox:
Me.Number = 1
DoCmd.OpenForm "LRU Data", acNormal, , , acFormAdd
Next Form:
If Forms!LRUChoices.Number.Text = 1 Then Me.RecordSource = AFT

And I get an error: "You can't reference a property or method for a control unless the control has the focus". I've seen examples online but they quite frankly make no sense.

Any help would be great!
 
You can use the OpenArgs property of the OpenForm method to pass information between the calling form and the form being called. The OpenArgs can then be tested in the On Load event of the form being called.
 
You can use the OpenArgs property of the OpenForm method to pass information between the calling form and the form being called. The OpenArgs can then be tested in the On Load event of the form being called.

This makes absolutely no sense to me and is why I was trying my unorthodox method.
Sub Button_Click()
DoCmd.OpenForm "LRU Data", acNormal, , , acFormAdd, acWindowNormal, "Number"

Private Sub Form_Load()
Dim strNumbers As String
strNumbers = Forms!LRUChoices.Number.Text.OpenArgs

If Len(strNumbers) = 1 Then Me.RecordSource = AFT

Doesn't work. I have no idea how to use OpenArgs and trying to copy what I've seen on the page and modify it to fit my names doesn't work.

:banghead:
 
Last edited:
On your calling form's Button you have;
Code:
DoCmd.OpenForm "LRU Data", acNormal, , , acFormAdd, acWindowNormal, [COLOR="Magenta"]"Number"[/COLOR]
The highlighted portion of that code is exactly what is going to be passed in the OpenArgs to the form being called. It could be a fixed string as it currently is, or it could be the value held in a control on that form, in which case you would use Me.YourControlName in place of "Number".

Now in the On Load event of the form being called you put something along the lines of;
Code:
If OpenArgs = "Number" Then
      Me.RecordSource = AFT
Else
     Me.RecordSource = AlternateTableName
End If

As an aside avoid using spaces and other special characters in Object and Control Names. They just make your life more complex than it need be. Also consider implementing a naming protocol along the lines of; TBL_TableName, FRM_FormName, QRY_QueryName etc. This schema makes it clear what type of object AFT is for example; I've presumed that it is a table but it could equally be a query :confused:
 
There is a sample here that demonstrates how OpenArgs can be used. Have a look at the Double Click event of Combo2 on FRM_Records and the On Load event of FRM_Items. The code is fully explained in the comments.
 
Ok, so I found a way to cheat. Apparently .value doesn't require a focus.

If Forms!LRUChoices!Number.Value = 1 Then RecordSource = "AFT"

with my hidden textbox on the first form yields the results I need. Been at this issue for days...On to the next one!:D
 
There is a sample here that demonstrates how OpenArgs can be used. Have a look at the Double Click event of Combo2 on FRM_Records and the On Load event of FRM_Items. The code is fully explained in the comments.

Thanks, going to read through this to get a better understanding of it.
 

Users who are viewing this thread

Back
Top Bottom