ReInitialize after running code 
Author Message
 ReInitialize after running code

I have a Form (frmHome).  On this form there is a button (cmd_View).
When the user clicks cmd_View, another form opens up (View_Permit).
There is a combo box (cmb_permitnum) that is populated from an
existing Access database by recordset key.  The user clicks a search
button (cmdSearchStatus) and I have it so Access opens to the form
corresponding to the value in cmb_permitnum.  That's all good.  When
the user closes Access, I wanted the user to be able to choose another
number in cmb_permitnum, but it errors out saying OpenForm is not
available.  I dont know why because Access should be closed at this
point.  So, I tried just having the form (View_Permit) close and  go
back to the frmHome so that you could click the button and do another
search...but when I do this, and when the form (View_Permit) opens,
the combo box now has nothing in it.  ?????????

Here is my code:
Private Sub cmdSearchStatus_Click()

Dim acc As Access.Application
Set acc = New Access.Application
acc.OpenCurrentDatabase "C:\Documents and Settings\Administrator\My
Documents\Tracking System Project\Permit_011009.mdb"
acc.DoCmd.OpenForm "permit_info"
acc.Visible = True

DoCmd.OpenForm "permit_info", , , "permit_num = " & "'" &
cmb_permitnum & "'", , acDialog
MsgBox ("Click OK when done viewing Access form.")
'Access form stays open while MsgBox is open
DoCmd.Close acForm, "permit_info"
acc.Application.Quit
Cancel = True
Unload Me
End Sub

Any suggestions?



Fri, 01 Jul 2011 12:55:23 GMT  
 ReInitialize after running code


Quote:
>I have a Form (frmHome).  On this form there is a button (cmd_View).
> When the user clicks cmd_View, another form opens up (View_Permit).
> There is a combo box (cmb_permitnum) that is populated from an
> existing Access database by recordset key.  The user clicks a search
> button (cmdSearchStatus) and I have it so Access opens to the form
> corresponding to the value in cmb_permitnum.  That's all good.  When
> the user closes Access, I wanted the user to be able to choose another
> number in cmb_permitnum, but it errors out saying OpenForm is not
> available.  I dont know why because Access should be closed at this
> point.  So, I tried just having the form (View_Permit) close and  go
> back to the frmHome so that you could click the button and do another
> search...but when I do this, and when the form (View_Permit) opens,
> the combo box now has nothing in it.  ?????????

> Here is my code:
> Private Sub cmdSearchStatus_Click()

> Dim acc As Access.Application
> Set acc = New Access.Application
> acc.OpenCurrentDatabase "C:\Documents and Settings\Administrator\My
> Documents\Tracking System Project\Permit_011009.mdb"
> acc.DoCmd.OpenForm "permit_info"
> acc.Visible = True

> DoCmd.OpenForm "permit_info", , , "permit_num = " & "'" &
> cmb_permitnum & "'", , acDialog
> MsgBox ("Click OK when done viewing Access form.")
> 'Access form stays open while MsgBox is open
> DoCmd.Close acForm, "permit_info"
> acc.Application.Quit
> Cancel = True
> Unload Me
> End Sub

> Any suggestions?

I think, this behavior is because you mix usage of local object acc with
hidden global Access Application object. Try to qualify the calls to DoCmd
methods with an "acc." variable name and, most likely, the problem will
gone. Additionally, I don't understand why do you open the same form
"permit_info" twice - but anyway this by itself is not the cause of your
immediate problem.

Dmitriy.



Sat, 02 Jul 2011 00:31:50 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. running code from Access that runs code in an excel spreadsheet

2. Closing and reinitializing user form

3. reinitialize a public object

4. Reinitialize the date

5. Form-Level variables don't reinitialize

6. How to reinitialize an array?

7. Error in Reinitializing Microsoft Internet Transfer control

8. Code to schedule modules to run every hour (or multiple daily runs)

9. Control code to only run at run-time.

10. Code running in design time or run-time?

11. Native Code vs P-Code run differently (VB5.0 SP3)

12. Run Code, Insert Code ??

 

 
Powered by phpBB® Forum Software