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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with form opening form

Status
Not open for further replies.

PenelopeC

Technical User
May 12, 2003
72
0
0
US
Can someone please take a look at this and help me?

I have a form frmPROJECT with an unbound list box containing a string from a query. When I click on the command button to enter data for a new project, I want the unbound list box contents to go into a control called "txtPROJ_IDAdd" on the frmPROJECT_UPDATE. The code I have is below but I keep getting an "Invalid use of Null" message. If I click on the list box first to highlight the control and THEN click the cmdADDPROJ button -- it works. How do I get the focus to the list box so the user doesn't have to be trained to click the list box before clicking the button?

TIA!

<snip>

Private Sub cmdADDPROJ_Click()
On Error GoTo Err_cmdADDPROJ_Click

Dim stDocName As String
Dim strPROJ_IDAdd As String

stDocName = "frmPROJECTADD"

'Store the project id from the list box
strPROJ_IDAdd = Forms!frmPROJECT!lstNextProj_id

'Open frmPROJECTADD
DoCmd.OpenForm stDocName, , , acFormEdit

'Populate the project id number
Forms!frmPROJECTADD!txtPROJ_IDAdd = strPROJ_IDAdd


Exit_cmdADDPROJ_Click:
Exit Sub

Err_cmdADDPROJ_Click:
MsgBox Err.DESCRIPTION
Resume Exit_cmdADDPROJ_Click

End Sub

</snip>

PenelopeC
~~~>-/O~~~~~swimming right along
 
In answer to your question, you can use:

Code:
Forms!frmPROJECT!lstNextProj_id.SetFocus

However, it seems you may have a bit more of an issue if it requires the focus before it will work.

One idea would be to look at using the OpenArgs statement on the OpenForm command.

Let me know if you need more than just a nudge :)
 
It comes up null -- is it because the control is unbound?

Thanks for your input -- I appreciate any help I can get figuring this out. I know just enough to be dangerous :D

PenelopeC
~~~>-/O~~~~~swimming right along
 
After looking at your original statement, then your code, I figured it out.

Change:
Code:
Forms!frmPROJECTADD!txtPROJ_IDAdd = strPROJ_IDAdd

to:
Code:
Forms!frmPROJECT_UPDATE!txtPROJ_IDAdd = strPROJ_IDAdd

I've tested the code and it works fine for me after I changed the form name.
 
DOH! I made a mistake in my original post. *growls at self*

The form I'm opening is frmPROJECTADD, not frmPROJECT_UPDATE. Don't know what I was thinking.

I'm sorry :(

For some reason, the control returns a NULL value and the messages when I put break points in say "Microsoft Access cannot find the object Forms!frmPROJECTADD...."

man do i need help -- feeling kinda goofy.

PenelopeC
~~~>-/O~~~~~swimming right along
 
From the sounds of it, you still have something misreferenced. Double check your form names, and double check control NAMES (not sources - common mistake).

As I said in my last post, your code as originally presented, works fine in a dummy run for me. I just created two forms using the names you had set forth, and added named controls. Copy/pasted your code, and no problems.

You could try: Forms!frmPROJECTADD.txtPROJ_IDAdd (switch the second ! with .)

Beyond that and double checking all of your references (step through each bit of your code), I'm running out of ideas.
 
Try putting a breakpoint on this line...
strPROJ_IDAdd = Forms!frmPROJECT!lstNextProj_id

to determine the value you're getting. Then try using the .ItemSelected or .Column(#) arguments with the lstNextProj_id listbox.


Randy
 
O.K. I feel really dumb, but where do I put arguments for a list box?

I put my break at that line and that's where I get the "NULL"

I've set the focus on the control, but my code only works if you click on the control THEN click on the command button.

Weird...and making me crazy :[]

PenelopeC
~~~>-/O~~~~~swimming right along
 
Okay. For some reason I kept trying to use a combobox instead of a listbox.

Is the listbox a required field (I assume so, as the command button requires a value to pass on).

One way to fix it, would be to set a default value for the field. OR, use:

Code:
strPROJ_IDAdd = nz(Forms!frmPROJECT!lstNextProj_id, 0)

NZ will convert a null value to the value after the comma, so that a value is always passed along.

Now, for some clarification.... since your listbox contains the results of a query, is there ever more than one option? If there is, I assume you want someone to select something from the listbox before pressing the button, in which case I'd throw up a msgbox letting the user know when an item is not chosen. Use the below code if this is the route you prefer to go:

Code:
Private Sub cmdADDPROJ_Click()
On Error GoTo Err_cmdADDPROJ_Click

    Dim stDocName As String
    Dim strPROJ_IDAdd As String

    stDocName = "frmPROJECTADD"
    
    If (Forms!frmPROJECT!lstNextProj_id & "") = "" Then
        MsgBox "Please select a project ID.", , "Project ID error"
        Exit Sub
    Else
        'Store the project id from the list box
        strPROJ_IDAdd = Forms!frmPROJECT!lstNextProj_id
        
        'Open frmPROJECTADD
        DoCmd.OpenForm stDocName, , , acFormEdit
    
        'Populate the project id number
        Forms!frmPROJECTADD!txtPROJ_IDAdd = strPROJ_IDAdd
    End If
    

Exit_cmdADDPROJ_Click:
    Exit Sub

Err_cmdADDPROJ_Click:
    MsgBox Err.Description
    Resume Exit_cmdADDPROJ_Click
End Sub

Good luck
 
Hello, everybody,
I have almost the same problem. I need to open a form from a subform with On Click event. I want the new form to be opened shows the one complete invoice, matching the invoice number of the subform.
This is my code:

Private Sub Invoice_Click()
DoCmd.OpenForm "frmViewInvoices", , , "[MatterID]" = " Forms![frmMainMenu]![frmInvoiceNumberList].[MatterID]"
End Sub

The new form opens, but there is no way to match the invoice number!!! Something wrong with my “WhereCondition” syntax.
Please help me at this point. Thanks
 
Nacar,
Did you figure this out? Your statement should be

"[MatterID] =" & Forms!frmMainMenu!frmInvoiceNumberList!MatterID

I'm assuming that frmInvoiceNumberList is a subform on frmMainMenu, in which case the above is correct, but if its not then you only need reference the form that the actual MatterID control is on.

PenelopeC
~~~>-/O~~~~~swimming right along
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top