Printing out single record w/comand button

E

Eswift

I am trying to Build an Event using Visual Basic so when
you click on a command button it prints out the report I
created for that single record only. I am using the last
name field as the primary key, but it does not seem to be
working? What am I missing??? Thank you in advance for
any help you can provide.

Dim stDoc As String
Dim stWhere As String
stDoc = "CMCRReport"
stWhere = "Last Name = " & Me.Last Name
DoCmd.OpenReport stDoc, , , stWhere

Private Sub Print_Report_Click()

End Sub
 
M

Marshall Barton

Eswift said:
I am trying to Build an Event using Visual Basic so when
you click on a command button it prints out the report I
created for that single record only. I am using the last
name field as the primary key, but it does not seem to be
working? What am I missing??? Thank you in advance for
any help you can provide.

Dim stDoc As String
Dim stWhere As String
stDoc = "CMCRReport"
stWhere = "Last Name = " & Me.Last Name
DoCmd.OpenReport stDoc, , , stWhere


Presumably Last Name is a Text type field so you need quotes
around it (doubled because they're already in quotes.

Since you have a space in the field name, you have to
enclose it in square brackets (it's best to stick to using
only alphanumeric characters in names).

stWhere = "[Last Name] = """ & Me.Last Name & """"
 
G

Guest

-----Original Message-----
Eswift said:
I am trying to Build an Event using Visual Basic so when
you click on a command button it prints out the report I
created for that single record only. I am using the last
name field as the primary key, but it does not seem to be
working? What am I missing??? Thank you in advance for
any help you can provide.

Dim stDoc As String
Dim stWhere As String
stDoc = "CMCRReport"
stWhere = "Last Name = " & Me.Last Name
DoCmd.OpenReport stDoc, , , stWhere


Presumably Last Name is a Text type field so you need quotes
around it (doubled because they're already in quotes.

Since you have a space in the field name, you have to
enclose it in square brackets (it's best to stick to using
only alphanumeric characters in names).

stWhere = "[Last Name] = """ & Me.Last Name & """"
--
Marsh
MVP [MS Access]
.
OK, First of all thank you very much for your help
AGAIN! Obviously I am just learning how to use the more
complicated items, at least they are for me! Now that I
have added an add record button under the print command
button. The Print Button has the same "Code Builder" pop
up with the add record code in it? Do I just add the
Print button code underneath? I took it out because I
couldn't get anything to work. Here is the working add
record code:
Private Sub Add_record_Click()
On Error GoTo Err_Add_record_Click


DoCmd.GoToRecord , , acNewRec

Exit_Add_record_Click:
Exit Sub

Err_Add_record_Click:
MsgBox Err.Description
Resume Exit_Add_record_Click

End Sub

Private Sub Print_Report_Click()
**DO I ADD IT HERE??**********************************
Dim stDoc As String
Dim stWhere As String
stDoc = "CMCRReport"
stWhere = "[Last Name] = """ & Me.Last Name & """"
DoCmd.OpenReport stDoc, , , stWhere
****************************************************
End Sub


Thanks again for your help, it is truly appreciated!!
 
G

Guest

I attempted to run it as shown, and I get a compile
error: Unexpected End of statement.

It points to the """ & Me.Last Name & """"
-----Original Message-----
-----Original Message-----
Eswift said:
I am trying to Build an Event using Visual Basic so when
you click on a command button it prints out the report I
created for that single record only. I am using the last
name field as the primary key, but it does not seem to be
working? What am I missing??? Thank you in advance for
any help you can provide.

Dim stDoc As String
Dim stWhere As String
stDoc = "CMCRReport"
stWhere = "Last Name = " & Me.Last Name
DoCmd.OpenReport stDoc, , , stWhere


Presumably Last Name is a Text type field so you need quotes
around it (doubled because they're already in quotes.

Since you have a space in the field name, you have to
enclose it in square brackets (it's best to stick to using
only alphanumeric characters in names).

stWhere = "[Last Name] = """ & Me.Last Name & """"
--
Marsh
MVP [MS Access]
.
OK, First of all thank you very much for your help
AGAIN! Obviously I am just learning how to use the more
complicated items, at least they are for me! Now that I
have added an add record button under the print command
button. The Print Button has the same "Code Builder" pop
up with the add record code in it? Do I just add the
Print button code underneath? I took it out because I
couldn't get anything to work. Here is the working add
record code:
Private Sub Add_record_Click()
On Error GoTo Err_Add_record_Click


DoCmd.GoToRecord , , acNewRec

Exit_Add_record_Click:
Exit Sub

Err_Add_record_Click:
MsgBox Err.Description
Resume Exit_Add_record_Click

End Sub

Private Sub Print_Report_Click()
**DO I ADD IT HERE??**********************************
Dim stDoc As String
Dim stWhere As String
stDoc = "CMCRReport"
stWhere = "[Last Name] = """ & Me.Last Name & """"
DoCmd.OpenReport stDoc, , , stWhere
****************************************************
End Sub


Thanks again for your help, it is truly appreciated!!
.
 
M

Marshall Barton

I attempted to run it as shown, and I get a compile
error: Unexpected End of statement.

Didn't I explain about using names with spaces or other
funky characters? Yeah, sure I did, I just didn't follow my
own advice:

stWhere = "[Last Name] = """ & Me.[Last Name] & """"

Note that the code for the new record button must be in its
own procedure and has nothing to do with the print button
procedures.
--
Marsh
MVP [MS Access]



It points to the """ & Me.Last Name & """"
-----Original Message-----
-----Original Message-----
Eswift wrote:

I am trying to Build an Event using Visual Basic so when
you click on a command button it prints out the report I
created for that single record only. I am using the last
name field as the primary key, but it does not seem to be
working? What am I missing??? Thank you in advance for
any help you can provide.

Dim stDoc As String
Dim stWhere As String
stDoc = "CMCRReport"
stWhere = "Last Name = " & Me.Last Name
DoCmd.OpenReport stDoc, , , stWhere


Presumably Last Name is a Text type field so you need quotes
around it (doubled because they're already in quotes.

Since you have a space in the field name, you have to
enclose it in square brackets (it's best to stick to using
only alphanumeric characters in names).

stWhere = "[Last Name] = """ & Me.Last Name & """"
--
Marsh
MVP [MS Access]
.
OK, First of all thank you very much for your help
AGAIN! Obviously I am just learning how to use the more
complicated items, at least they are for me! Now that I
have added an add record button under the print command
button. The Print Button has the same "Code Builder" pop
up with the add record code in it? Do I just add the
Print button code underneath? I took it out because I
couldn't get anything to work. Here is the working add
record code:
Private Sub Add_record_Click()
On Error GoTo Err_Add_record_Click


DoCmd.GoToRecord , , acNewRec

Exit_Add_record_Click:
Exit Sub

Err_Add_record_Click:
MsgBox Err.Description
Resume Exit_Add_record_Click

End Sub

Private Sub Print_Report_Click()
**DO I ADD IT HERE??**********************************
Dim stDoc As String
Dim stWhere As String
stDoc = "CMCRReport"
stWhere = "[Last Name] = """ & Me.Last Name & """"
DoCmd.OpenReport stDoc, , , stWhere
****************************************************
End Sub


Thanks again for your help, it is truly appreciated!!
.
 
G

Guest

** I do not know why I didn't see that myself? Sorry...
It works wonderfully. Thank you so much for all your
help. You need a raise, consider it done! ha ha ha **

-----Original Message-----
I attempted to run it as shown, and I get a compile
error: Unexpected End of statement.

Didn't I explain about using names with spaces or other
funky characters? Yeah, sure I did, I just didn't follow my
own advice:

stWhere = "[Last Name] = """ & Me.[Last Name] & """"

Note that the code for the new record button must be in its
own procedure and has nothing to do with the print button
procedures.
--
Marsh
MVP [MS Access]



It points to the """ & Me.Last Name & """"
-----Original Message-----

-----Original Message-----
Eswift wrote:

I am trying to Build an Event using Visual Basic so
when
you click on a command button it prints out the report
I
created for that single record only. I am using the
last
name field as the primary key, but it does not seem to
be
working? What am I missing??? Thank you in advance for
any help you can provide.

Dim stDoc As String
Dim stWhere As String
stDoc = "CMCRReport"
stWhere = "Last Name = " & Me.Last Name
DoCmd.OpenReport stDoc, , , stWhere


Presumably Last Name is a Text type field so you need
quotes
around it (doubled because they're already in quotes.

Since you have a space in the field name, you have to
enclose it in square brackets (it's best to stick to
using
only alphanumeric characters in names).

stWhere = "[Last Name] = """ & Me.Last Name & """"
--
Marsh
MVP [MS Access]
.
OK, First of all thank you very much for your help
AGAIN! Obviously I am just learning how to use the more
complicated items, at least they are for me! Now that I
have added an add record button under the print command
button. The Print Button has the same "Code Builder" pop
up with the add record code in it? Do I just add the
Print button code underneath? I took it out because I
couldn't get anything to work. Here is the working add
record code:
Private Sub Add_record_Click()
On Error GoTo Err_Add_record_Click


DoCmd.GoToRecord , , acNewRec

Exit_Add_record_Click:
Exit Sub

Err_Add_record_Click:
MsgBox Err.Description
Resume Exit_Add_record_Click

End Sub

Private Sub Print_Report_Click()
**DO I ADD IT HERE??**********************************
Dim stDoc As String
Dim stWhere As String
stDoc = "CMCRReport"
stWhere = "[Last Name] = """ & Me.Last Name & """"
DoCmd.OpenReport stDoc, , , stWhere
****************************************************
End Sub


Thanks again for your help, it is truly appreciated!!
.

.
 
M

Marshall Barton

** I do not know why I didn't see that myself? Sorry...
It works wonderfully. Thank you so much for all your
help. You need a raise, consider it done! ha ha ha **


LOL, all positive rewards are welcome, but this is strictly
a voluntary activity ;-)

Glad you got it working, but I'll still nag you about those
funky names ;-)
--
Marsh
MVP [MS Access]


-----Original Message-----
I attempted to run it as shown, and I get a compile
error: Unexpected End of statement.

Didn't I explain about using names with spaces or other
funky characters? Yeah, sure I did, I just didn't follow my
own advice:

stWhere = "[Last Name] = """ & Me.[Last Name] & """"

Note that the code for the new record button must be in its
own procedure and has nothing to do with the print button
procedures.
--
Marsh
MVP [MS Access]



It points to the """ & Me.Last Name & """"

-----Original Message-----

-----Original Message-----
Eswift wrote:

I am trying to Build an Event using Visual Basic so
when
you click on a command button it prints out the report
I
created for that single record only. I am using the
last
name field as the primary key, but it does not seem to
be
working? What am I missing??? Thank you in advance for
any help you can provide.

Dim stDoc As String
Dim stWhere As String
stDoc = "CMCRReport"
stWhere = "Last Name = " & Me.Last Name
DoCmd.OpenReport stDoc, , , stWhere


Presumably Last Name is a Text type field so you need
quotes
around it (doubled because they're already in quotes.

Since you have a space in the field name, you have to
enclose it in square brackets (it's best to stick to
using
only alphanumeric characters in names).

stWhere = "[Last Name] = """ & Me.Last Name & """"
--
Marsh
MVP [MS Access]
.
OK, First of all thank you very much for your help
AGAIN! Obviously I am just learning how to use the more
complicated items, at least they are for me! Now that I
have added an add record button under the print command
button. The Print Button has the same "Code Builder" pop
up with the add record code in it? Do I just add the
Print button code underneath? I took it out because I
couldn't get anything to work. Here is the working add
record code:
Private Sub Add_record_Click()
On Error GoTo Err_Add_record_Click


DoCmd.GoToRecord , , acNewRec

Exit_Add_record_Click:
Exit Sub

Err_Add_record_Click:
MsgBox Err.Description
Resume Exit_Add_record_Click

End Sub

Private Sub Print_Report_Click()
**DO I ADD IT HERE??**********************************
Dim stDoc As String
Dim stWhere As String
stDoc = "CMCRReport"
stWhere = "[Last Name] = """ & Me.Last Name & """"
DoCmd.OpenReport stDoc, , , stWhere
****************************************************
End Sub


Thanks again for your help, it is truly appreciated!!
.

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top