sql vba variables recordset

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Access VBA Training and help » Using both fields/columns selected in combo box | Access forum

Using both fields/columns selected in combo box | Access forum

resolvedResolved · Low Priority · Version 2003

Edited on Sat 8 May 2010, 19:55

Mark has attended:
Access Intermediate course
Access Advanced course
Access VBA course

Using both fields/columns selected in combo box

Hi,

I am studying the code from the vba course. I have a combo box cmbEmployee and we made it load with the Employee ID field (hidden by zero column width) and the Employee name for the user to select. The ID is taken (by way of default) to store in the intEmployee variable.

The bit I am interested in is the label for the sales analysis output. Currently I have sales of the product selected and "by employee 4" for example. I want to obtain a second variable from the combo selection so that I can show the name and not the ID here.

I have inserted Dim strEmployee As String to be in addition to Dim intEmployee as Integer but would love to know how I obtain the employee name for the string whilst still also having the integer variable.

Thanking you in anticipation --
Regards, Mark

RE: Using both fields/columns selected in combo box

I have luckily come across the same problem posted by someone else on another forum. To access the other columns in the combo box one can use the .column(col no) reference. The first column is 0. Hence for my two column combo I got two values to play with using the following.

intEmployee = Me.cmbEmployee.Value
strEmployeeName = Me.cmbEmployee.Column(1)

Regards, Mark

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Access tip:

Calculating The Difference Between Dates

If you wish to calculate the time between two date fields, this can be done in a number of ways:

1. As a calculated field in a query
2. As a calculated control in a form or report
3. As a calculation in a VBA procedure.

The basic syntax to get the number of days between two dates is:

=[One Date Field] - [Another Date Field]

You can also use one of the following functions:

=Month([One Date Field] - [Another Date Field])
which calculates the number of months between the two fields

=Year([One Date Field] - [Another Date Field])
which calculates the number of years between the two fields.

Another function is the DateDiff() function.

It uses an argument to determine how the time interval is measured. For example:

=DateDiff("q",[One Date Field] - [Another Date Field])
returns the number of quarters between the two fields.

Other intervals that can be used in this expression are as follows:
"yyyy" - Years
"m" - Months
"d" - Days
"w" - Weekdays
"ww" - Weeks
"h" - Hours
"n" - Minutes
"s" - Seconds

View all Access hints and tips


Server loaded in 0.07 secs.