show records by user

G

Guest

I have a database that 5 people will be using. There is a field "txtName"
that pulls the nt login of the user. I want to create a form that has a drop
down box where I can select my "txtName" and it opens my "Tasks" form
displaying ONLY the records where the "txtName" is what I chose. For example:
In "Form1" I select joe.smith. That opens the form called "Tasks" and
displays all of the records that have joe.smith in the "txtName" field. This
can open by pressing a go button. How do I do that?
 
G

Graham Mandeno

Hi Am

Create a combo box, cboSelectUser, and set its RowSource to:
Select distinct txtName from YourTasksTable;

Then, in the code for your button's Click event, create a filter string if a
name has been selected, and use that to open the form:

Dim strFilter as String
If Not IsNull(cboSelectUser) then
strFilter = "txtName='" & cboSelectUser & "'"
' (note the embedded single quotes)
End If
DoCmd.OpenForm "YourTasksForm", , , strFilter
 
G

Guest

I did what you advised, but now the button just hides all records. Here is my
code:


button code:

Private Sub GoButton_Click()
On Error GoTo Err_GoButton_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70

Dim strFilter As String
If Not IsNull(cboSelectUser) Then
strFilter = "txtName='" & cboSelectUser & "'"
' (note the embedded single quotes)
End If
DoCmd.OpenForm "Tasks", , , strFilter

Exit_GoButton_Click:
Exit Sub

Err_GoButton_Click:
MsgBox Err.Description
Resume Exit_GoButton_Click

End Sub


Graham Mandeno said:
Hi Am

Create a combo box, cboSelectUser, and set its RowSource to:
Select distinct txtName from YourTasksTable;

Then, in the code for your button's Click event, create a filter string if a
name has been selected, and use that to open the form:

Dim strFilter as String
If Not IsNull(cboSelectUser) then
strFilter = "txtName='" & cboSelectUser & "'"
' (note the embedded single quotes)
End If
DoCmd.OpenForm "YourTasksForm", , , strFilter

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Am said:
I have a database that 5 people will be using. There is a field "txtName"
that pulls the nt login of the user. I want to create a form that has a
drop
down box where I can select my "txtName" and it opens my "Tasks" form
displaying ONLY the records where the "txtName" is what I chose. For
example:
In "Form1" I select joe.smith. That opens the form called "Tasks" and
displays all of the records that have joe.smith in the "txtName" field.
This
can open by pressing a go button. How do I do that?
 
G

Graham Mandeno

Hi Annemarie

What is the DoCmd.DoMenuItem line supposed to do? DoMenuItem is obsolete
and is just there for backwards compatibility (yes, I know the code
generated by the wizards uses it, but that's a sore point!) If you can say
what it is supposed to do, then we'll tell you the better way to do it.

Other than that, I can't see anything wrong with the code.

You could try adding the following temporary lines just before the
DoCmd.OpenForm:

Debug.Print strFilter
Stop

This will pause your code at that point, and in the Immediate window you
should see:

txtName='joe.smith'

Check that out and report back :)
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Annemarie said:
I did what you advised, but now the button just hides all records. Here is
my
code:


button code:

Private Sub GoButton_Click()
On Error GoTo Err_GoButton_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70

Dim strFilter As String
If Not IsNull(cboSelectUser) Then
strFilter = "txtName='" & cboSelectUser & "'"
' (note the embedded single quotes)
End If
DoCmd.OpenForm "Tasks", , , strFilter

Exit_GoButton_Click:
Exit Sub

Err_GoButton_Click:
MsgBox Err.Description
Resume Exit_GoButton_Click

End Sub


Graham Mandeno said:
Hi Am

Create a combo box, cboSelectUser, and set its RowSource to:
Select distinct txtName from YourTasksTable;

Then, in the code for your button's Click event, create a filter string
if a
name has been selected, and use that to open the form:

Dim strFilter as String
If Not IsNull(cboSelectUser) then
strFilter = "txtName='" & cboSelectUser & "'"
' (note the embedded single quotes)
End If
DoCmd.OpenForm "YourTasksForm", , , strFilter

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Am said:
I have a database that 5 people will be using. There is a field
"txtName"
that pulls the nt login of the user. I want to create a form that has a
drop
down box where I can select my "txtName" and it opens my "Tasks" form
displaying ONLY the records where the "txtName" is what I chose. For
example:
In "Form1" I select joe.smith. That opens the form called "Tasks" and
displays all of the records that have joe.smith in the "txtName" field.
This
can open by pressing a go button. How do I do that?
 
G

Guest

I removed that line and it still hides all records. Here is my code now:

Private Sub GoButton_Click()
On Error GoTo Err_GoButton_Click

Dim strFilter As String
If Not IsNull(cboSelectUser) Then
strFilter = "txtName='" & cboSelectUser & "'"
' (note the embedded single quotes)
End If
DoCmd.OpenForm "Tasks", , , strFilter

Exit_GoButton_Click:
Exit Sub

Err_GoButton_Click:
MsgBox Err.Description
Resume Exit_GoButton_Click

End Sub

Graham Mandeno said:
Hi Annemarie

What is the DoCmd.DoMenuItem line supposed to do? DoMenuItem is obsolete
and is just there for backwards compatibility (yes, I know the code
generated by the wizards uses it, but that's a sore point!) If you can say
what it is supposed to do, then we'll tell you the better way to do it.

Other than that, I can't see anything wrong with the code.

You could try adding the following temporary lines just before the
DoCmd.OpenForm:

Debug.Print strFilter
Stop

This will pause your code at that point, and in the Immediate window you
should see:

txtName='joe.smith'

Check that out and report back :)
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Annemarie said:
I did what you advised, but now the button just hides all records. Here is
my
code:


button code:

Private Sub GoButton_Click()
On Error GoTo Err_GoButton_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70

Dim strFilter As String
If Not IsNull(cboSelectUser) Then
strFilter = "txtName='" & cboSelectUser & "'"
' (note the embedded single quotes)
End If
DoCmd.OpenForm "Tasks", , , strFilter

Exit_GoButton_Click:
Exit Sub

Err_GoButton_Click:
MsgBox Err.Description
Resume Exit_GoButton_Click

End Sub


Graham Mandeno said:
Hi Am

Create a combo box, cboSelectUser, and set its RowSource to:
Select distinct txtName from YourTasksTable;

Then, in the code for your button's Click event, create a filter string
if a
name has been selected, and use that to open the form:

Dim strFilter as String
If Not IsNull(cboSelectUser) then
strFilter = "txtName='" & cboSelectUser & "'"
' (note the embedded single quotes)
End If
DoCmd.OpenForm "YourTasksForm", , , strFilter

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

I have a database that 5 people will be using. There is a field
"txtName"
that pulls the nt login of the user. I want to create a form that has a
drop
down box where I can select my "txtName" and it opens my "Tasks" form
displaying ONLY the records where the "txtName" is what I chose. For
example:
In "Form1" I select joe.smith. That opens the form called "Tasks" and
displays all of the records that have joe.smith in the "txtName" field.
This
can open by pressing a go button. How do I do that?
 
G

Guest

I take back the last one. I removed both DoCmd lines, so my code looks like
this:

Private Sub GoButton_Click()
On Error GoTo Err_GoButton_Click

Dim strFilter As String
If Not IsNull(cboSelectUser) Then
strFilter = "txtName='" & cboSelectUser & "'"
' (note the embedded single quotes)
End If

Exit_GoButton_Click:
Exit Sub

Err_GoButton_Click:
MsgBox Err.Description
Resume Exit_GoButton_Click

End Sub

Now when I choose a user from my drop down box and press go, nothing happens.

Graham Mandeno said:
Hi Annemarie

What is the DoCmd.DoMenuItem line supposed to do? DoMenuItem is obsolete
and is just there for backwards compatibility (yes, I know the code
generated by the wizards uses it, but that's a sore point!) If you can say
what it is supposed to do, then we'll tell you the better way to do it.

Other than that, I can't see anything wrong with the code.

You could try adding the following temporary lines just before the
DoCmd.OpenForm:

Debug.Print strFilter
Stop

This will pause your code at that point, and in the Immediate window you
should see:

txtName='joe.smith'

Check that out and report back :)
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Annemarie said:
I did what you advised, but now the button just hides all records. Here is
my
code:


button code:

Private Sub GoButton_Click()
On Error GoTo Err_GoButton_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70

Dim strFilter As String
If Not IsNull(cboSelectUser) Then
strFilter = "txtName='" & cboSelectUser & "'"
' (note the embedded single quotes)
End If
DoCmd.OpenForm "Tasks", , , strFilter

Exit_GoButton_Click:
Exit Sub

Err_GoButton_Click:
MsgBox Err.Description
Resume Exit_GoButton_Click

End Sub


Graham Mandeno said:
Hi Am

Create a combo box, cboSelectUser, and set its RowSource to:
Select distinct txtName from YourTasksTable;

Then, in the code for your button's Click event, create a filter string
if a
name has been selected, and use that to open the form:

Dim strFilter as String
If Not IsNull(cboSelectUser) then
strFilter = "txtName='" & cboSelectUser & "'"
' (note the embedded single quotes)
End If
DoCmd.OpenForm "YourTasksForm", , , strFilter

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

I have a database that 5 people will be using. There is a field
"txtName"
that pulls the nt login of the user. I want to create a form that has a
drop
down box where I can select my "txtName" and it opens my "Tasks" form
displaying ONLY the records where the "txtName" is what I chose. For
example:
In "Form1" I select joe.smith. That opens the form called "Tasks" and
displays all of the records that have joe.smith in the "txtName" field.
This
can open by pressing a go button. How do I do that?
 
G

Graham Mandeno

Hi Annemarie
Now when I choose a user from my drop down box and press go, nothing
happens.

Well, that is because you removed the DoCmd.OpenForm line, so the form is no
longer opening :)

Did you insert the two diagnostic lines I suggested?

If so, what was the result?

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Annemarie said:
I take back the last one. I removed both DoCmd lines, so my code looks like
this:

Private Sub GoButton_Click()
On Error GoTo Err_GoButton_Click

Dim strFilter As String
If Not IsNull(cboSelectUser) Then
strFilter = "txtName='" & cboSelectUser & "'"
' (note the embedded single quotes)
End If

Exit_GoButton_Click:
Exit Sub

Err_GoButton_Click:
MsgBox Err.Description
Resume Exit_GoButton_Click

End Sub

Now when I choose a user from my drop down box and press go, nothing
happens.

Graham Mandeno said:
Hi Annemarie

What is the DoCmd.DoMenuItem line supposed to do? DoMenuItem is obsolete
and is just there for backwards compatibility (yes, I know the code
generated by the wizards uses it, but that's a sore point!) If you can
say
what it is supposed to do, then we'll tell you the better way to do it.

Other than that, I can't see anything wrong with the code.

You could try adding the following temporary lines just before the
DoCmd.OpenForm:

Debug.Print strFilter
Stop

This will pause your code at that point, and in the Immediate window you
should see:

txtName='joe.smith'

Check that out and report back :)
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Annemarie said:
I did what you advised, but now the button just hides all records. Here
is
my
code:


button code:

Private Sub GoButton_Click()
On Error GoTo Err_GoButton_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70

Dim strFilter As String
If Not IsNull(cboSelectUser) Then
strFilter = "txtName='" & cboSelectUser & "'"
' (note the embedded single quotes)
End If
DoCmd.OpenForm "Tasks", , , strFilter

Exit_GoButton_Click:
Exit Sub

Err_GoButton_Click:
MsgBox Err.Description
Resume Exit_GoButton_Click

End Sub


:

Hi Am

Create a combo box, cboSelectUser, and set its RowSource to:
Select distinct txtName from YourTasksTable;

Then, in the code for your button's Click event, create a filter
string
if a
name has been selected, and use that to open the form:

Dim strFilter as String
If Not IsNull(cboSelectUser) then
strFilter = "txtName='" & cboSelectUser & "'"
' (note the embedded single quotes)
End If
DoCmd.OpenForm "YourTasksForm", , , strFilter

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

I have a database that 5 people will be using. There is a field
"txtName"
that pulls the nt login of the user. I want to create a form that
has a
drop
down box where I can select my "txtName" and it opens my "Tasks"
form
displaying ONLY the records where the "txtName" is what I chose. For
example:
In "Form1" I select joe.smith. That opens the form called "Tasks"
and
displays all of the records that have joe.smith in the "txtName"
field.
This
can open by pressing a go button. How do I do that?
 

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