pswilliams0
Registered User.
- Local time
- Today, 07:56
- Joined
- Apr 19, 2012
- Messages
- 20
Hi,
I'm currently in the midst of my first foray into the access world. I'm making big strides, but also trying to extensively customize the project...
What I have right now is a command bar that has buttons that open up an variety of forms and reports. The data I am dealing with are reports that need to be written. These reports get assigned to an Author and then have a due date. I have a table of authors, and the main table of all the open reports that need to be written. I can run the query to display any open report. However, I would like to limit this same report output based on the author assigned to the report. So, an author could print out his current "open" reports.
To do this, I created a combo box of all the authors (about 20), then created a command button to open the report. Unfortunately, I keep getting syntax errors. Here is my VBA:
___________________________________________________
Private Sub Command28_Click()
On Error GoTo Err_Command28_Click
Dim stDocName As String
MsgBox AuthorSelection
stDocName = "Open QN Items Report"
DoCmd.OpenReport stDocName, acPreview, , "QN Author= '" & Me.AuthorSelection & "'"
Exit_Command28_Click:
Exit Sub
Err_Command28_Click:
MsgBox Err.Description
Resume Exit_Command28_Click
End Sub
______________________________________________
So, I have all of the authors listed in the combo box (named AuthorSelection) as Last, First names (one Field Item in Author table). I think this might be my problem, but I'm not really sure how to fix it. These names display in many other reports and forms without a problem.
As you can see in the code, I threw in a MsgBox. From that I only ever get the last name from the combo box. So, as an example: I select "Smith, John" from the combo box, then click the button to run the code shown above. I would get a MsgBox that displays the AuthorSelection as "Smith" NOT "Smith, John"
The second problem is the Syntax Error I get after closing the MsgBox:
"Syntax Error (missing operator) in query or expression '(QN Author= 'Smith')'.
"QN Author" is the field in the report I'm trying to filter.
So there are two problems:
1. Why is the combo box only recognizing the last name (or text before the comma)
2. What is my syntax error? Is it that the recognized name doesn't match any of the fields in the report exactly? (Because the QN Author field has format "Last, First" ?
Thanks for any expertise/guidance you're able to offer!
I'm currently in the midst of my first foray into the access world. I'm making big strides, but also trying to extensively customize the project...
What I have right now is a command bar that has buttons that open up an variety of forms and reports. The data I am dealing with are reports that need to be written. These reports get assigned to an Author and then have a due date. I have a table of authors, and the main table of all the open reports that need to be written. I can run the query to display any open report. However, I would like to limit this same report output based on the author assigned to the report. So, an author could print out his current "open" reports.
To do this, I created a combo box of all the authors (about 20), then created a command button to open the report. Unfortunately, I keep getting syntax errors. Here is my VBA:
___________________________________________________
Private Sub Command28_Click()
On Error GoTo Err_Command28_Click
Dim stDocName As String
MsgBox AuthorSelection
stDocName = "Open QN Items Report"
DoCmd.OpenReport stDocName, acPreview, , "QN Author= '" & Me.AuthorSelection & "'"
Exit_Command28_Click:
Exit Sub
Err_Command28_Click:
MsgBox Err.Description
Resume Exit_Command28_Click
End Sub
______________________________________________
So, I have all of the authors listed in the combo box (named AuthorSelection) as Last, First names (one Field Item in Author table). I think this might be my problem, but I'm not really sure how to fix it. These names display in many other reports and forms without a problem.
As you can see in the code, I threw in a MsgBox. From that I only ever get the last name from the combo box. So, as an example: I select "Smith, John" from the combo box, then click the button to run the code shown above. I would get a MsgBox that displays the AuthorSelection as "Smith" NOT "Smith, John"
The second problem is the Syntax Error I get after closing the MsgBox:
"Syntax Error (missing operator) in query or expression '(QN Author= 'Smith')'.
"QN Author" is the field in the report I'm trying to filter.
So there are two problems:
1. Why is the combo box only recognizing the last name (or text before the comma)
2. What is my syntax error? Is it that the recognized name doesn't match any of the fields in the report exactly? (Because the QN Author field has format "Last, First" ?
Thanks for any expertise/guidance you're able to offer!