Code assistance

  • Thread starter Thread starter ladybug via AccessMonster.com
  • Start date Start date
L

ladybug via AccessMonster.com

I have a code that I found that I am trying to modify to my database. This
is the code:

Private Sub Command15_Click()
On Error GoTo Err_Command15_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Timesheet"

stLinkCriteria = "[EmployeeName]=" & "'" & Me![cboSearch] & "'"
stLinkCriteria = "[WeekRange]=" & "'" & Me![Text22] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

I have a form with two combo boxes. The first one is cboSearch where you
select an Employee. The second is Text22 where you select a weekrange. Once
both selections are made the on click code for the command button has this
Event Procedure and it opens another form. I want the Employee and Weekrange
selected in the first form, to populate when opening the second form.

Right now with the code above it is only reading the WeekRange. No matter
what EmployeeName I select it only shows the first Employee name from my
table.

Any suggestions?
 
ladybug said:
I have a code that I found that I am trying to modify to my database. This
is the code:

Private Sub Command15_Click()
On Error GoTo Err_Command15_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Timesheet"

stLinkCriteria = "[EmployeeName]=" & "'" & Me![cboSearch] & "'"
stLinkCriteria = "[WeekRange]=" & "'" & Me![Text22] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

I have a form with two combo boxes. The first one is cboSearch where you
select an Employee. The second is Text22 where you select a weekrange. Once
both selections are made the on click code for the command button has this
Event Procedure and it opens another form. I want the Employee and Weekrange
selected in the first form, to populate when opening the second form.

Right now with the code above it is only reading the WeekRange. No matter
what EmployeeName I select it only shows the first Employee name from my
table.


You need to combine the criteria instead of resetting it.

stLinkCriteria = "EmployeeName='" & Me!cboSearch & "'" _
" AND WeekRange='" & Me!Text22 & "'"
 
I combined them and received a compile error.

Marshall said:
I have a code that I found that I am trying to modify to my database. This
is the code:
[quoted text clipped - 20 lines]
what EmployeeName I select it only shows the first Employee name from my
table.

You need to combine the criteria instead of resetting it.

stLinkCriteria = "EmployeeName='" & Me!cboSearch & "'" _
" AND WeekRange='" & Me!Text22 & "'"
 
ladybug said:
I combined them and received a compile error.

Marshall said:
I have a code that I found that I am trying to modify to my database. This
is the code:
[quoted text clipped - 20 lines]
what EmployeeName I select it only shows the first Employee name from my
table.

You need to combine the criteria instead of resetting it.

stLinkCriteria = "EmployeeName='" & Me!cboSearch & "'" _
" AND WeekRange='" & Me!Text22 & "'"


I wonder what your code looks like and which compile error
you received.
 
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Timesheet"

stLinkCriteria = "EmployeeName='" & Me!cboSearch & "'" _
" AND WeekRange='" & Me!Text22 & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Compile Error: Expected End of Statement


Marshall said:
I combined them and received a compile error.
[quoted text clipped - 8 lines]
I wonder what your code looks like and which compile error
you received.
 
ladybug said:
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Timesheet"

stLinkCriteria = "EmployeeName='" & Me!cboSearch & "'" _
" AND WeekRange='" & Me!Text22 & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Compile Error: Expected End of Statement


I don't see anything wrong. Are you sure that the error was
on one of those lines? You did use Copy/Paste to post the
code, right?

I suppose it's possible that some weird, invisible character
somehow got mixed in there. Try retyping it.
 
I tried it again and it says Compile error: Expected: line number or labelor
statement or end of statement.

This is what it looks like:
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Timesheet"

stLinkCriteria = "EmployeeName='" & Me!cboSearch & "'"
" AND WeekRange='" & Me!Text22 & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Timesheet"

stLinkCriteria = "EmployeeName='" & Me!cboSearch & "'" _
" AND WeekRange='" & Me!Text22 & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Compile Error: Expected End of Statement
[quoted text clipped - 4 lines]
I wonder what your code looks like and which compile error
you received.
 
I tried it again and it says Compile error: Expected: line number or labelor
statement or end of statement.

This is what it looks like:
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Timesheet"

stLinkCriteria = "EmployeeName='" & Me!cboSearch & "'"
" AND WeekRange='" & Me!Text22 & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


Marshall said:
Dim stDocName As String
Dim stLinkCriteria As String
[quoted text clipped - 6 lines]
Compile Error: Expected End of Statement

I don't see anything wrong. Are you sure that the error was
on one of those lines? You did use Copy/Paste to post the
code, right?

I suppose it's possible that some weird, invisible character
somehow got mixed in there. Try retyping it.
 
ladybug said:
I tried it again and it says Compile error: Expected: line number or labelor
statement or end of statement.

This is what it looks like:
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Timesheet"

stLinkCriteria = "EmployeeName='" & Me!cboSearch & "'"
" AND WeekRange='" & Me!Text22 & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


If this version is a Copy/Paste of your real code, then you
are missing the space underscore at the end of the first
line.
 
It is a copy/paste. I put the space and underscore in and now it highlights
the two lines and says Compile error: Syntax error.

Marshall said:
I tried it again and it says Compile error: Expected: line number or labelor
statement or end of statement.
[quoted text clipped - 8 lines]
" AND WeekRange='" & Me!Text22 & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

If this version is a Copy/Paste of your real code, then you
are missing the space underscore at the end of the first
line.
 
I tried it again and it says Compile error: Expected: line number or labelor
statement or end of statement.

This is what it looks like:
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Timesheet"

stLinkCriteria = "EmployeeName='" & Me!cboSearch & "'"
" AND WeekRange='" & Me!Text22 & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Marshall said:
Dim stDocName As String
Dim stLinkCriteria As String
[quoted text clipped - 6 lines]
Compile Error: Expected End of Statement
I don't see anything wrong. Are you sure that the error was
on one of those lines? You did use Copy/Paste to post the
code, right?
I suppose it's possible that some weird, invisible character
somehow got mixed in there. Try retyping it.

You need a _ at the end of the first line of your "stlinkcriteria ="
line.
 
ladybug said:
It is a copy/paste. I put the space and underscore in and now it highlights
the two lines and says Compile error: Syntax error.


It should also hightlight the portion of the line that the
compiler thinks is a problem. Be sure to use the Debug menu
- Compile option instead of just running something that
invokes the code.

As far as I can see, there was no syntax error beyond the
missing space underscore. Did you make any other changes.
It would probably help if you posted a Copy/Paste of what
you currently have.
 
Back
Top