Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open and closing forms 1

Status
Not open for further replies.

Dre313

Technical User
Jun 4, 2003
219
US
I have a form with a button that opens another form.. on form 1 when i hit to open form 2 I want form 1 to close.. leaving only form 2 visible...

how do i do that ?? thanks
 
just put this in after the section of code that opens form2

unload form1

or if you want to keep the form in memory just hide it with

form1.visible = false
 

Heres is my code behind the button that opens the new form
------------------------------------------
DoCmd.OpenForm "frmAddInspec", OpenArgs:=strProject & ";" & strArea & ";" & strReference


my form which has the button the open form "frmAddInspec" is called .. "frmSearch"


I put

Unload frmSearch at the end of the first part of my code and got an error... variable not defined.. What am i doing wrong ??

thanks for the response..
 
yea... it looks like this..



DoCmd.OpenForm "frmAddInspec", OpenArgs:=strProject & ";" & strArea & ";" & strReference
Unload frmSearch
 
hmm sounds a bit odd, what version are you using and what reference libraries do you have loaded in VBA?
 
I'm using access 97.. what do you mean reference libraries.. sorry kinda new.. thanks
 
ah silly me, have a look in the project explorer section on the left of the screen and see what the name of your form is there it's probably summat like form_frmsearch try that instead
 
I changed it to form_frmSearch... I'm getting a different error.. ActiveX component can't create object...

Did i do something wrong ??

thanks
 
can you tell me if frmsearch has a module attached to it?
there is a property you can check called HasModule
 
I check the form property it set at yes already
 
oh bugger sorry, I've been thinking VB syntax not VBA, try docmd.close acform, Form_FrmSearch
 
hmmm I get a different error this time.. Run-time error 2498 An expression you enter is the wrong data type for one of the arguments...

what could be wrong ?
 
that would normally mean something like you were trying to close a report but had told it to look for a form, if no playing about with the code works you could try using a macro instead maybe? they're just as quick and a lot easier to set up if you don't like coding
 
Yes.. What's going on is.. on my form1 I'm pulling a specific record that the user specifies.. then continuously Im pulling info from form1 and transferring it to form2 so that the user can fill out the rest of the info. I'm using a module to do that..

Is there not another way to just close the form when i open form2.. wouldnt know where to start with wat you suggested...


thanks
 
ok then, your options are:

get the docmd.close line to work, this shouldn't be acting up as you say it is, you could try inserting this line with no arguments BEFORE the line which opens up form2 as docmd.close on its own closes the current object although the code in my previous post should work.

You could just hide form1 with form1.visible = false

I really do think that docmd.close acform, form_frmsearch
is the best option, when it pops up with an error click help instead and see if that gives you a hint as to why it's not working.

oh and the first line you've got up there doesn't look quite right, should there not be a load more commas before your openargs statement, I think it should look something like:
DoCmd.OpenForm Form_frmaddinspec,,,,,,OpenArgs:=strProject & ";" & strArea & ";" & strReference
as you seem to have the args in the section which tells it wether to open in design mode etc.
 
RivetHed,

I think I got it... heres what i did..

DoCmd.Close acForm, "frmSearch"


it works !! thanks for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top