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

Print From Second Form

Status
Not open for further replies.

wreded

Technical User
Dec 18, 2001
119
US
i have a main form that has a mark for delete button on it. (i've taken to just "marking" records for deletion instead of just deleting them outright.) Prior to marking for deletion i have a popup form come up asking to print the record. It's a simple "yes/no" form. "No" i've got, "yes" is giving some trouble. i've got the print to select only the current record (thanks to the FAQs). When i select the "yes" button i get an error telling me that "MS Access can't find the field 'Name' referred to in your expression."
How do i get an expression through this secondary form? i can do without it, but it's a nice touch.
Thanks,
Dave
 
How are you attempting to print the report? Do you have a field named name which is a poor name since every object has a name property which causes naming confusion?

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
i have a main form with several buttons. One button marks the record for deletion. When pressed it calls the second form with two (Yes/No) buttons; one to print the record, one just cancels. On pressing "Yes", print the record i get the error. "Name" i just used to show the error i am getting.
 
I was hoping to see some code or SQL or whatever. What you have reiterated doesn't help.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Oh, sorry...
"Yes" button:
Code:
Private Sub btn_PrintRcd_Click()
On Error GoTo Err_Btn_SingleRpt_Click

    Dim stDocName As String
    Dim stCriteria As String
    
    stDocName = "rptIndivTng"
    stCriteria = "[IndvName] = '" & Me![IndvName] & "'"
    DoCmd.OpenReport stDocName, acPreview, , stCriteria
Exit_Btn_SingleRpt_Click:
    Exit Sub
Err_Btn_SingleRpt_Click:
    MsgBox Err.Description
    Resume Exit_Btn_SingleRpt_Click
End Sub
As You can see it's pretty straight forward. i guess what i'm trying to do is to call through an intervening form and i don't know how to do that.

Dave
 
The calling code looks like:

Code:
Private Sub Btn_DelRcd_Click()
Dim Response

If Gone Then
    Response = MsgBox("You can't deleted an individual who is gone.", vbOKOnly + vbCritical, "Can't Delete")
    Exit Sub
End If

;if not already deleted then mark as deleted
If Not Rcd_Del Then
    Me.Rcd_Del = True
    Me.Lbl_Deleted.Visible = True    ;turn on deleted label
    Me.Btn_RealDelete.Visible = True ;turn on delete button
    Me.Btn_RealDelete.Enabled = True ;enable delete button
    DoCmd.OpenForm "frmYes_No"     ;open form to print record
;this is to undelete a record
ElseIf Rcd_Del Then
    Me.Rcd_Del = False
    Me.Lbl_Deleted.Visible = False
    Me.Btn_RealDelete.Visible = False
    Me.Btn_RealDelete.Enabled = False
End If
End Sub

There's nothing really fancy here, just labels that display on the form to tell users if a person is gone and turning on a "real" delete button to remove a record permanently.

Thanks,
Dave
 
Is the actual prompt for a field "IndvName"? Is there a IndvName field in the record source of frmYes_No?

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Yes, on Your recommendation i changed the field name from "Name" to "IndvName." Inherited programs are hard to debug or enhance when there is no documentation within them.
Dave
 
1) Is there a field named "IndvName" in your form's record source?
2) Is there a field name "IndvName" in your report's record source?

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
I am surprised that your Yes/No form has any record source. If it does have a record source, how would it open to the appropriate record for deletion with this code:
Code:
   DoCmd.OpenForm "frmYes_No"
Have you attempted to set a breakpoint and step through your code?

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
i'm sorry, i'm getting a little frustrated here. i think You're trying to make me see something that i can't yet see.
Let me try to get back to basics here:
FormA: Data form
BtnA: Delete button
FormB: Print/Delete form
BtnB: Print button

If press BtnA, FormB popsup, if press BtnB, defined report prints.

FormB has no record source, that's in FormA. When pressing BtnB request to print should go back through FormA with required parameters to get record source and produce defined report.

Problem: When pressing BtnB error "Can't find field [IndvName]" and process halts. Record is properly marked for deletion but no print occurs.

That sums up my problem. What am i not seeing here?
Thanks,
Dave
 
This is exactly why I asked earlier
1) Is there a field named "IndvName" in your form's record source?
which you said yes. Apparently there is no recordsource of FormB so there can be no fields in the form's record source.

I would use this code to open frmYes_No where the IndvName is sent to the form as the OpenArgs.
Code:
 DoCmd.OpenForm "frmYes_No", , , , , , Me.IndvName
Then to use the openargs
Code:
Private Sub btn_PrintRcd_Click()
On Error GoTo Err_Btn_SingleRpt_Click

    Dim stDocName As String
    Dim stCriteria As String
    
    stDocName = "rptIndivTng"
    If Len(Me.OpenArgs & "") >0 Then
        stCriteria = "[IndvName] = '" & Me.OpenArgs & "'"
    End If
    DoCmd.OpenReport stDocName, acPreview, , stCriteria
Exit_Btn_SingleRpt_Click:
    Exit Sub
Err_Btn_SingleRpt_Click:
    MsgBox Err.Description
    Resume Exit_Btn_SingleRpt_Click
End Sub


Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Hey Duane can You hit me a couple more times with that 2X4? i think i may learn something if You do.
i got all wrapped up in the wrong form. Gotta think "FOCUS," and read some more of those darned books.
Thanks for setting me straight.
Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top