Dustin Stanley
asked on
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:
Now for the line Forms!CheckoutFormName!Ord erStatusID = "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.
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'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"
Now for the line Forms!CheckoutFormName!Ord
Thank you for the help.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
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.....
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.....
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.
Dustin,
Sometimes it is advantageous to send a form reference to a subroutine of function. a simple function would be something like:
Dale
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
This is not a very useful example, but gives you an idea of what Anders is talking about.Dale
ASKER
Ok I still don't understand.
In my example:
If frmNewOrdersGuestCheckout is open then wouldn't I need a sub that would say:
If frmNewOrder is open then wouldn't I need a sub that would say:
Wouldn't that defeat the purpose?????
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"
If frmNewOrdersGuestCheckout is open then wouldn't I need a sub that would say:
Forms!frmNewOrdersGuestCheckout !OrderStatusID = "7"
If frmNewOrder is open then wouldn't I need a sub that would say:
Forms!frmNewOrder!OrderStatusID = "7"
Wouldn't that defeat the purpose?????
ASKER
Thank you both for the help. I am interested in finding out if there is more to the sub that I understand. Love learning.
E.g.
Open in new window