MS Access Refer To Form With String Value

I am needing to use the same Code for multiple situations but I can not figure out one part. Here is a example:

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'LETS SEE WHICH CHECKOUT FORM IS OPEN SO WE CAN FILL IT OUT PROPERLY
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Dim CheckoutFormName As String
 Dim Receipt As String
 
If CurrentProject.AllForms("frmNewOrdersGuestCheckout").IsLoaded = True Then ' Guest Checkout Form is Open
CheckoutFormName = "frmNewOrdersGuestCheckout"
Receipt = "RptqryGuestCheckoutReceipt"
End If

If CurrentProject.AllForms("frmNewOrder").IsLoaded = True Then   ' Customer with account Form is Open
CheckoutFormName = "frmNewOrder"
Receipt = "RptqryCheckoutReceipt"
End If

Forms!CheckoutFormName!OrderStatusID = "7"

Open in new window



Now for the line Forms!CheckoutFormName!OrderStatusID = "7" how would I set it up to get Access to find and accept the the String (CheckoutFormName) as a form?

Thank you for the help.
LVL 1
Dustin StanleyEntrepreneurAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
Forms(strFormName).OrderStatusID
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
I don't know what the calling point of your code is. But note that you can pass a form object to your code, to ensure that you always have the right reference.
E.g.
Call SomeCode(me)

Public sub SomeCode(frm as form)
  'Some other stuff might go here
  frm!OrderStatusID!value=7
end Sub

Open in new window

0
Dustin StanleyEntrepreneurAuthor Commented:
Dale that works Perfect!

Anders Can you please explain better. The form that is open sometimes is different (Varying). So how can calling to another sub be beneficial?

Wouldn't I have to have a varying call if that makes sense.....
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
What is the starting point of your code? What triggers it? What scenario are you trying to solve. Then I could better put the explanation of the technique in context of your situation.
0
Dale FyeOwner, Developing Solutions LLCCommented:
Dustin,

Sometimes it is advantageous to send a form reference to a subroutine of function.  a simple function would be something like:

Public Function FormControlCount(frm as form) as integer

    FormControlCount = frm.controls.Count

End Function

Open in new window

This is not a very useful example, but gives you an idea of what Anders is talking about.

Dale
0
Dustin StanleyEntrepreneurAuthor Commented:
Ok I still don't understand.

In my example:
Dim CheckoutFormName As String
 Dim Receipt As String
 
If CurrentProject.AllForms("frmNewOrdersGuestCheckout").IsLoaded = True Then ' Guest Checkout Form is Open
CheckoutFormName = "frmNewOrdersGuestCheckout"
Receipt = "RptqryGuestCheckoutReceipt"
End If

If CurrentProject.AllForms("frmNewOrder").IsLoaded = True Then   ' Customer with account Form is Open
CheckoutFormName = "frmNewOrder"
Receipt = "RptqryCheckoutReceipt"
End If

Forms!CheckoutFormName!OrderStatusID = "7"

Open in new window



If frmNewOrdersGuestCheckout is open then wouldn't I need a sub that would say:
Forms!frmNewOrdersGuestCheckout !OrderStatusID = "7"

Open in new window



If frmNewOrder is open then wouldn't I need a sub that would say:
Forms!frmNewOrder!OrderStatusID = "7"

Open in new window



Wouldn't that defeat the purpose?????
0
Dustin StanleyEntrepreneurAuthor Commented:
Thank you both for the help. I am interested in finding out if there is more to the sub that I understand. Love learning.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.