Open new form based on combobox selection (1 Viewer)

mort

Registered User.
Local time
Today, 05:47
Joined
Mar 19, 2018
Messages
30
Hello all!

I am not an expert in programming, but I manage simple VBA coding in Access.

I have used the last few days searching online for a solution to my problem, but still havent found one. I think the solution is quite simple, i just cant figure out what it might be.

I am building a database for my employer. Its goal is to keep track of inventory. The different items in inventory differs greatly, and one have to add details to each inventory based on its type.

Right now I have a main form to register each item, and when the general registration if finished you choose what kind of item it is from a combobox. I have 11 different choices in the combobox.

What i want is to open a new form based on the selection the user makes in the combobox.

My code is this:

Dim strform as String
If Me.CboName = "Choice1" Then
strform = "OpenForm1"
ElseIf Me.CboName = "Choice2" Then
strform = "Openform2"
Elseif Me.CboName = "Choice 3" Then
strform = "Openform3"
End if
Docmd.openform strform

This code works fine when i use 1 IF-statement (end the code after strmform= "Openform1"), but it fails when i add more statements (Ii get error message "Run-time error '2494.: You have to assign a form-argument for the action").

What is wrong with mye code? Can someone please help me.
 
Last edited by a moderator:

jdraw

Super Moderator
Staff member
Local time
Today, 00:47
Joined
Jan 23, 2006
Messages
15,393
Watch this free video on Stock management for info on Inventory system design.

Inventory is not a trivial subject, and certainly not a good choice for a first database. I don't know your background or environment but hopefully you have done some research;your analysis and created a model(s) identifying the processes and the data model that you can test and adjust as necessary. I would advise you to not jump to physical database until you have tested and confirmed your data model with sample scenarios.

For info on comboboxes see this from TechOnTheNet.

Good luck with your project.

Note: After posting, or even when searching /browsing forum threads, look at the bottom of the page/screen for a list of similar or related posts.
 

mort

Registered User.
Local time
Today, 05:47
Joined
Mar 19, 2018
Messages
30
Maybe inventory was not the best word to use. I work in the police and I am making a databse for registering and viewing items in evidence. There will be a different database from case to case, so the total number of registrations will range between 200-500 items.

Thank you for your help. I will look at the video and articles.

But still, no one can see anything wrong with my code?
 

1268

Registered User.
Local time
Yesterday, 23:47
Joined
Oct 11, 2012
Messages
44
Hello all!

I am not an expert in programming, but I manage simple VBA coding in Access.

I have used the last few days searching online for a solution to my problem, but still havent found one. I think the solution is quite simple, i just cant figure out what it might be.

I am building a database for my employer. Its goal is to keep track of inventory. The different items in inventory differs greatly, and one have to add details to each inventory based on its type.

Right now I have a main form to register each item, and when the general registration if finished you choose what kind of item it is from a combobox. I have 11 different choices in the combobox.

What i want is to open a new form based on the selection the user makes in the combobox.

My code is this:

Dim strform as String
If Me.CboName = "Choice1" Then
strform = "OpenForm1"
ElseIf Me.CboName = "Choice2" Then
strform = "Openform2"
Elseif Me.CboName = "Choice 3" Then
strform = "Openform3"
End if
Docmd.openform strform

This code works fine when i use 1 IF-statement (end the code after strmform= "Openform1"), but it fails when i add more statements (Ii get error message "Run-time error '2494.: You have to assign a form-argument for the action").

What is wrong with mye code? Can someone please help me.

Make a cross reference table. Where your selection = the form to open. Then use dlookup to set the value of your variable strform.

Strform = Nz(dlookup([columnnamewhereuhaveformname],"tablename", "choicecolumn = '" & strform & "' "), msgbox "not found")

Air code so I am sure the syntax needs help but you get the idea.

There are several other probably better solutions to do what you want but from where you are at this is easiest.

Sent from my SM-G950U using Tapatalk
 

mort

Registered User.
Local time
Today, 05:47
Joined
Mar 19, 2018
Messages
30
Hello all!

I am not an expert in programming, but I manage simple VBA coding in Access.

I have used the last few days searching online for a solution to my problem, but still havent found one. I think the solution is quite simple, i just cant figure out what it might be.

I am building a database for my employer. Its goal is to keep track of inventory. The different items in inventory differs greatly, and one have to add details to each inventory based on its type.

Right now I have a main form to register each item, and when the general registration if finished you choose what kind of item it is from a combobox. I have 11 different choices in the combobox.

What i want is to open a new form based on the selection the user makes in the combobox.

My code is this:



This code works fine when i use 1 IF-statement (end the code after strmform= "Openform1"), but it fails when i add more statements (Ii get error message "Run-time error '2494.: You have to assign a form-argument for the action").

What is wrong with mye code? Can someone please help me.


I found out what was wrong with my code - the combobox selection is case sensitive. Thats why the IF-statement failed, because i did not capitalize the first letter in the cbo-selection.

I see that i get advice to do this differently. Is my way a bad way of doing this?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:47
Joined
May 7, 2009
Messages
19,246
Rename each form as with the name of its corresponding item in the combo with a prefix "frm", eg

List item: "choice1"
Your cirrespoding form name: "frmchoice1"

Then you open the form (without IFs):
Docmd.openform "frm" & me.cboName
 

Users who are viewing this thread

Top Bottom