linking forms

tamirka

New Member
Joined
Nov 7, 2002
Messages
40
Hi guys,
I have a form " main_form" . when opened , an inputbox pop up so a user type the market he want to enter. If , for example, chicago is enterd, i want the form " chicago " to open....if the market doesn't exist ...an error message....
please help ASAP :cry:
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi Tamirka,

Here's how Access likes you to do it:

Code:
Private Sub Form_Open()
On Error GoTo Err_Open

    Dim stDocName As String

    stDocName = inputbox("Please enter market...")
    DoCmd.OpenForm stDocName

Exit_Err_Open:
    Exit Sub

Err_Open:
    MsgBox("Market does not exist")
    Resume Exit_Err_Open
    
End Sub

HTH,
 
Upvote 0
Sorry, I'm mixing up my Excel and Access code,

Try this, I tested it this time :eek:

Private Sub Form_Load()
On Error GoTo Err_Open

Dim stDocName As String

stDocName = InputBox("Please enter market...")
DoCmd.OpenForm stDocName

Exit_Err_Open:
Exit Sub

Err_Open:
MsgBox ("Market does not exist")
Resume Exit_Err_Open

End Sub

HTH,
 
Upvote 0
Corticus,
thank you for your help..
I ahve this problem now. When I enter a wrong market the message box do not close ever. I have to close access ....now i cannot open the database since the inputbox pop up when it is open.... :x
 
Upvote 0
I was unable to replicate this problem,

If I just click 'ok' on the message box, it closes.

Why do you have to close Access? I don't see why displaying a message box would cause Access to freeze up but maybe I am missing something.


Perhaps if I walk you through the code you can isolate your problem
Code:
Private Sub Form_Load() 
'go to Err_open if an error occurs
On Error GoTo Err_Open

'identify variable to hold form to be opened's name
Dim stDocName As String 

'request form's name from user as save as stDocName
stDocName = InputBox("Please enter market...") 
'open this form, chance for error here if form not found, so Err_Open is called
DoCmd.OpenForm stDocName 

'this is the common exit point for the procedure
Exit_Err_Open: 
Exit Sub 

'this is where the error for no form is handled
Err_Open:
'here's your message box
MsgBox ("Market does not exist") 
'go to common exit point ffor form, Exit_Err_Open
Resume Exit_Err_Open

End Sub

BTW, to prevent code from executing when you open your db, hold shift down when you open it.

HTH,
 
Upvote 0
Also, off the subject, in order to avoid errors, you might want to consider first loading in a small form with a combo box populated with all available markets in it so that the user cannot possibly break your system. When User selects his market, your main form loads in with all appropriate "Market" records. This is a good rule of thumb for any application, make it as idiot proof as you possibly can by using list and combo boxes. I don't know about your current expertise, but if you'd like an example, tell us.
 
Upvote 0
great, it works now,
what happened is I added a code to close the main form when the city in question open.
thank you for the tip" shift and open"..I couldn't figure out how to get to my code :D
thanks again
talk 2 you later for sure
I' gonna check out" Theofficeexperts.com
 
Upvote 0
oh pleas eI woul dlike an example..
I use to program with VB about 6 years ago...so I 'm trying to refresh my mind..plus Iwork with access at work all the time...
I can understand the language....but I 'm having hard time starting my own codes and stuff
appreciate it :wink:
 
Upvote 0

Forum statistics

Threads
1,221,526
Messages
6,160,340
Members
451,637
Latest member
hvp2262

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top