Solved Open a form whose name is in a combobox on a form (1 Viewer)

Sam Summers

Registered User.
Local time
Today, 12:41
Joined
Sep 17, 2001
Messages
939
Surely this isn't hard but I just cannot find what i am looking for!

When the user clicks on a save button of a form i want another form to open whose name is the text (Location) from the combobox (LocationRef) on the the current form.

So basically there are forms called by the name of every location that are in the combobox list which is based on a Table of locations.

Hope that makes sense?

Many thanks in advance
 

Minty

AWF VIP
Local time
Today, 12:41
Joined
Jul 26, 2013
Messages
10,355
Assuming your combo is called LocationRef and the Location is the bound column?

Code:
DoCmd.OpenForm Me.LocationRef

Although having a specific form for a value sounds like a poor design choice.
What happens if you need to add a location? Create another form?
 

Sam Summers

Registered User.
Local time
Today, 12:41
Joined
Sep 17, 2001
Messages
939
Assuming your combo is called LocationRef and the Location is the bound column?

Code:
DoCmd.OpenForm Me.LocationRef

Although having a specific form for a value sounds like a poor design choice.
What happens if you need to add a location? Create another form?
Hi Minty and thank you

What i did was this:

Code:
Dim Location As String
   
Location = Me.LocationRef.Column(1)
   
If IsNull("DescriptionRef") Or IsNull("LocationRef") Then
    Cancel = True
    Else
        DoCmd.OpenForm Location

Which worked as well but i found out why it wasn't working - Some of the names of the forms have spaces in between them which i am trying to figure out how to get round?

Unless i name the forms numbers and add a column in the combobox with the numbers that the user wont see?
 

SHANEMAC51

Active member
Local time
Today, 15:41
Joined
Jan 28, 2022
Messages
310
Which worked as well but i found out why it wasn't working - Some of the names of the forms have spaces in between them which i am trying to figure out how to get round?
try
Code:
try DoCmd.OpenForm """" & Location & """"
 

Minty

AWF VIP
Local time
Today, 12:41
Joined
Jul 26, 2013
Messages
10,355
Which worked as well but i found out why it wasn't working - Some of the names of the forms have spaces in between them which i am trying to figure out how to get round?

Unless i name the forms numbers and add a column in the combobox with the numbers that the user wont see?
I wouldn't do that. How would you remember what form 1 did in six months...?

A form name should be something descriptive and easy to reference e.g. frmClientData, frmProducts, sfrmOrderLines.

Create a table with the location you want to display and the appropriate form name as a second column. Or add a column to your locations data with the actual form name and add that as another hidden column to your combo.

I still think this sounds like a bit of a design disaster waiting to happen.
 

Sam Summers

Registered User.
Local time
Today, 12:41
Joined
Sep 17, 2001
Messages
939
I wouldn't do that. How would you remember what form 1 did in six months...?

A form name should be something descriptive and easy to reference e.g. frmClientData, frmProducts, sfrmOrderLines.

Create a table with the location you want to display and the appropriate form name as a second column. Or add a column to your locations data with the actual form name and add that as another hidden column to your combo.

I still think this sounds like a bit of a design disaster waiting to happen.
Yes, point taken.

Think i will work on that now i have a better idea of how to achieve it.

Many thanks everyone
 

SHANEMAC51

Active member
Local time
Today, 15:41
Joined
Jan 28, 2022
Messages
310
When the user clicks on a save button of a form i want another form to open whose name is the text (Location) from the combobox (LocationRef) on the the current form.
Apparently you made a mistake with the name of the form - all spaces and quotes/apostrophes work fine

Code:
Private Sub combobox1_Click()
Dim s1
s1 = Me.combobox1 & ""
If Len(s1) > 0 Then
DoCmd.OpenForm s1, acNormal
End If
End Sub
 

Attachments

  • U220223ABBA.png
    U220223ABBA.png
    22.7 KB · Views: 223

Users who are viewing this thread

Top Bottom