A
Aria
I've run into a bit of a problem. It didn't work. Please tell me where I'm
going wrong. I input the following into the Afterupdate event:
Dim rs As Object
Set rs = Me.RecordsetClone
rs.FindFirst "[LastName, FirstName] = " & Me.cboStaffLookup
Me.Bookmark = rs.Bookmark
or should it say," rs.FindFirst "[LastName], [FirstName] = " &
Me.cboStaffLookup ?
I'm getting the following message:
"Micorsoft Access can't find the macro 'Dim rs As Object
Set rs=Me
The macro (or its macro group) doesn't exist, or the macro is new but hasn't
been save. Note that when you enter the macrogroupname, macroname syntax in
an argument, yu must specify the name the macro's macro group was last saved
under."
So, I went to macros and didn't get beyond "Find Record". I didn't know what
else to do there or if I even needed to be there since it wasn't mentioned.
I didn't see anything unusual other than what I already mentioned about the
#14 listed under title description. There were no drop-down arrows in
datasheet view nor did the Lookup tab show "Combo Box". It said text box for
Class Description, Title Description, LN, FN and MI. Is this a problem? When
I go to frmEmployees, Class Description is a combo box. Title Description is
a subform.
Your explanation was fine. It answered the question I posed. Thanks.
--
Aria W.
going wrong. I input the following into the Afterupdate event:
Dim rs As Object
Set rs = Me.RecordsetClone
rs.FindFirst "[LastName, FirstName] = " & Me.cboStaffLookup
Me.Bookmark = rs.Bookmark
or should it say," rs.FindFirst "[LastName], [FirstName] = " &
Me.cboStaffLookup ?
I'm getting the following message:
"Micorsoft Access can't find the macro 'Dim rs As Object
Set rs=Me
The macro (or its macro group) doesn't exist, or the macro is new but hasn't
been save. Note that when you enter the macrogroupname, macroname syntax in
an argument, yu must specify the name the macro's macro group was last saved
under."
So, I went to macros and didn't get beyond "Find Record". I didn't know what
else to do there or if I even needed to be there since it wasn't mentioned.
Yes, look in tblEmployees if that contains the records that are not sorting
properly. Regarding the drop-down arrow, I meant in datasheet view. It
will show up when you click into the field. In Design view, the Lookup tab
at the bottom of the window will show "Combo Box".
I didn't see anything unusual other than what I already mentioned about the
#14 listed under title description. There were no drop-down arrows in
datasheet view nor did the Lookup tab show "Combo Box". It said text box for
Class Description, Title Description, LN, FN and MI. Is this a problem? When
I go to frmEmployees, Class Description is a combo box. Title Description is
a subform.
Your explanation was fine. It answered the question I posed. Thanks.
--
Aria W.
BruceM said:Aria said:Hi Bruce,
Thanks for responding. It seemed so easy in the example. Why does
everything
have to turn into a problem? I'm sorry, I forgot to include column widths.
I
thought about that much later.
Column widths =0";0.6459";0.625"
List widths=1.2708"
My mistake. It's list width that sets the overall width.
In this case it should be unbound. You aren't trying to store the value,
but rather to go to the selected record.
I thought it should be unbound but I've been wrong so often that now I
automatically think, "You're wrong. It must be the other way."
Dim rs As Object
Set rs = Me.RecordsetClone
rs.FindFirst "[EmployeeID] = " & Me.cboEmployee
Me.Bookmark = rs.Bookmark
Hmmm...programming code. You know where I am as far as skill level. I am
certainly willing to try, if you don't mind the questions that are sure to
come. I'll try not to inundate you with a thousand and one questions.
Can I ask the following:
1. The above code goes into the AfterUpdate event as is?
Use your actual control and field names, but other than that it should work
as written.
2. Well, maybe I don't need to know, but I was wondering if Access already
knows that rs is an abbreviation for Me.RecordsetClone because the = sign
isn't used until the second statement. If it's more than I need to know,
we
can drop it.
Here is a simpler example of using a variable. This is a string (text)
variable:
' This declares that when strMsg appears in the code it is to be treated as
a text string
Dim strMsg as String
' This assigns a value to the string variable we have just declared
strMsg = "You are about to change the value"
' The next two lines of code will produce the same message
MsgBox "You are about to change the value"
MsgBox strMsg
If this code is in the Before Update event for a text box the message "You
are about to change the value" will appear before the value is updated.
Using the variable can be tidier, and simplifies things when you need to use
the same text string several times. In the VBA examples in VBA Help all
values are assigned to variables. I can't say I see the benefit of that,
but it may help to understand what's going on with Help.
In my example, Dim rs As Object declares to the After Update event that rs
is an Object. I can't really describe why RecordsetClone is an Object, nor
can I clearly describe what RecordsetClone is. However, this line of code
tells the After Update event that rs is the same as Me.RecordsetClone:
Set rs = Me.RecordsetClone3. Me.Bookmark--I've seen that before and have been dying to ask. What
does
that do? I think of a bookmark as a placeholder, but if the value isn't
stored...?
For one thing, it's very different from a Bookmark in Word. This
explanation may be a bit sketchy, but it's the best I can do. Form VBA
Help, a bookmark "uniquely identifies a particular record in the form's
underlying table". This:
rs.FindFirst "[EmployeeID] = " & Me.cboEmployee
identifies a particular record in the form's record source. A bookmark is
assigned to each record in the Record Source table or query. RecordsetClone
is a copy of the Recordset, so it has the same bookmarks. RecordsetClone
lets you perform actions such as Find that cannot be performed on the form.
Once the particular record you selected is identified in the copy
(RecordsetClone), Me.Bookmark = rs.Bookmark goes to the record with the same
bookmark as the one that was found in the RecordsetClone.
That's the best I can do with that one.
Again, if you don't want to get into it, that's fine.
As far as the SQL statement, I opened it again in Design view and this is
what it shows:
Field: EmpID
Table:tblEmployees
Show: Yes (The box is checked).
Field:Last Name
Table:tblEmployees
Sort: Ascending
Show: Yes
Field: FirstName
Table:tblEmployees
Sort: Ascending
Show: Yes
Just want to make sure we're on the same page...I'm working in
frmEmployees
with subform SiteEmps, so the table you want me to look in is
tblEmployees?
Just to cover all, I checked both tables. I did not see a drop-down arrow.
I
assume you mean in Design View. There is something a little odd though. I
have only input 6 employee names using frmEmployees just so I can check to
see if things are working. When I opened the table, 5 of the employees
have a
title description (Admin., teacher, etc.). The sixth and final entry shows
a
#...#14. I don't know why. When you open the form, it list the title.
Yes, look in tblEmployees if that contains the records that are not sorting
properly. Regarding the drop-down arrow, I meant in datasheet view. It
will show up when you click into the field. In Design view, the Lookup tab
at the bottom of the window will show "Combo Box". I couldn't say what is
going on with #...#14.
As far as printing the record, I am just trying to circumvent some
anticipated issues; one in particular is staying in my head. As I work
through my issues with the db, I keep thinking about how others will use
it.
I can hear some of the conversations already. I did think about making a
report after I created that button. The print button is convenient but I
think I would rather it go to print preview. I don't know, I'm still just
trying to get through all of my other issues.
You can preview the report with something like this:
DoCmd.OpenReport "ReportName", acViewPreview
The menu bar or toolbar can contain the print command or icon.--
Aria W.
BruceM said:I can't figure why it isn't sorting, although I have one idea I will
address
later. Try this:
SELECT [EmpID], [LastName] & ", " & [FirstName] AS LastFirst FROM
tblEmployees ORDER BY
[LastName], [FirstName];
This doesn't really address your questions in some ways, but it is an
example of how an alias (LastFirst) can be used. You didn't mention
column
widths, but for a three column colmbo box in which the first column is
hidden then would be something like 0";1";1". In my example the column
count would be 2 and the column widths 0";1". From what I can tell the
rightmost visible column will fill the rest of the space in the combo
box.
If there is one visible column it will be the width of the combo box
unless
its width is greater than the combo box width. If the combo box is 2.5"
wide and the visible columns are 1";1" the rightmost column will actually
be
1.5". If the combo box is 1.5" wide and the visible columns are 1";1"
the
rightmost column will hang over the edge of the combo box when you click
the
down arrow.
Anyhow, back to the combo box. In this case it should be unbound. You
aren't trying to store the value, but rather to go to the selected
record.
For this the combo box needs an After Update event something like this
(cboEmployee is the name of the combo box):
Dim rs As Object
Set rs = Me.RecordsetClone
rs.FindFirst "[EmployeeID] = " & Me.cboEmployee
Me.Bookmark = rs.Bookmark
You could also do it this way:
Me.RecordsetClone.FindFirst "[EmployeeID] = " & Me.cboEmployee
Me.Bookmark = Me.RecordsetClone.Bookmark
The difference is that in the first case rs is used as a sort of
abbreviation for Me.RecordsetClone. Thereafter you use rs in place of
Me.RecordsetClone. Dim rs as Object declares rs as an object variable.
I
don't want to get too deeply into this, but when you hear about variable
declaration and use, this is one example.
Back to the sorting in the combo box. Open the SQL in Design View and be
sure it is what it should be. Unless there is a lookup field in the
table,
it should work. To see if there is a lookup field, open the table and
see
if any of the fields have a drop-down arrow. If they do, report back
about
it. It needs to be fixed.
Assuming you get the combo box to work as intended, just what action are
you
performing when you print the record? Best choice would be to create a
report (it can be very simple if you like), and to print the report. It
is
an easy enough matter to limit printing the report to a single selected
record.
Apparently there are problems in the Microsoft forum. I hate to break
the
thread (sorry Bruce) but I was wondering if you could help me with
something?
Currently, I'm working with frmEmployees. I want the form to be
user-friendly.
I know there are going to be issues there. There is an example of what
I
want
to do in my book and I followed what they said to do, but of course it
isn't
working for me. In frmEmployees I added a combo box. It's unbound;
maybe
it
should be bound. I did try that but it again only showed the last name.
What
I'm trying to do is create a drop-down list of employee last name,
first
name.
When the user clicks on the name, it goes to that employee record. I
added
a
print record button (I don't know if it works because currently, I'm
stuck
on
this). I see the names in the drop-down but it isn't going to that
record
and
when I click on the name it then only shows the last name.
This is the SQL statement: SELECT [tblEmployees].[EmpID],
[tblEmployees].
[LastName], [tblEmployees].[FirstName] FROM tblEmployees ORDER BY
[tblEmployees].[LastName], [tblEmployees].[FirstName];
The Record Source is tblEmployees. I tried to put Last name in as the
control
source but Access didn't like that so I took it out. The Row Source
Type
is
table/query. Column count = 3
Bound Column = 1
I'm sure we've already discussed this but I not catching it. I've
looked
at
the query. It looks like what I want. I've also looked at it in
datasheet
view. The names are there but it did not sort ascending like I asked.
What
mistakes have I made and how do I fix it?
Beetle284 wrote:
You may need to refresh my memory a bit here. You had m:m relationships
for Employees to Titles and Employees to Classifications, so you have
junction
tables for each of them, is that correct?
I was talking specifically about tables, not forms.
[quoted text clipped - 15 lines]
gonna
start :- )