By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,456 Members | 1,400 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,456 IT Pros & Developers. It's quick & easy.

Multi-List boxes and navigation

P: n/a
I'm developing an A2K adp that contains doctor info and the months
they are not available for teaching. A doctor can be unavailable for
some months for one year and other months for another year. I want
the user to enter the year then use a multi-select list box to choose
the months not available, then go to a fresh screen, enter another
year and choose the months not available for that year, and so on. In
the table, there is one record per year/month per doctor.

I've got the form set up and I can enter one year and the months but
can't figure out how to navigate to a fresh screen and enter the next
year. Maybe using a multi-select listbox isn't the way to go??? Any
ideas? Thanks.
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Ellen Manning wrote:
I'm developing an A2K adp that contains doctor info and the months
they are not available for teaching. A doctor can be unavailable for
some months for one year and other months for another year. I want
the user to enter the year then use a multi-select list box to choose
the months not available, then go to a fresh screen, enter another
year and choose the months not available for that year, and so on. In
the table, there is one record per year/month per doctor.

I've got the form set up and I can enter one year and the months but
can't figure out how to navigate to a fresh screen and enter the next
year. Maybe using a multi-select listbox isn't the way to go??? Any
ideas? Thanks.


Why not? I am not sure how many columns you have. You can see in my
example I use 0 as the first column is the column I want to use (the
column property starts at zero so if you have 5 columns, it is 0-4).

I would have a button to update the months to igrnore in the table.
Let's say your table has the fields called DoctorID, YearAvail, and the
months are Yes/No for availability and are called Jan...Dec. On the
form you have a DoctorID field you are working on, the YearAvail. The
listbox name is called ListMon. The listbox has 1 column; Jan...Dec

Sub CommandSelectAvailability_Click

'no need to process if doctorid or year is empty.
If IsNull(Me.DoctorID) Or IsNull(Me.YearAvail) Then Exit Sub

Dim var As Variant
Dim strMon As STring
Dim intFor As Integer
Dim intYear As Integer
Dim rst As DAO.Recordset

Set rst = Currentdb.openrecordset("Availability",dbopendynas et)

'find the doctor record for the year
rst.findfirst "DoctorID = " & Me.DoctorID & " And " _
"YearAvail = " & Me.YearAvail

'if found, edit the availablity record else add one.
If not rst.nomatch then
rst.Edit
Else
'if not found, create a new record
rst.AddNew
rst!DoctorID = Me.DoctorID
rst!Year = Me.YearAvail
Endif

'if editing, clear out any settings first
intYear = Year(Date())
For intFor = 1 to 12
'assign to variable Jan-Dec
strMon = Format(DateSerial(intYear,intFor,1),"mmm")

'now set that month to false
rst(strMon) = False
Next

'loop through all selected months and set to Available = True
For Each var In Me.ListMon.ItemsSelected
'assign the month to true
strMon = Me.ListMon.Column(0, var)
rst(strMon) = True

'now de-select that month
Me.ListMon.Selected(var) = False
Next

'commit the changes and close recordset
rst.Update
rst.close
set rst = Nothing

'clear out the Year
Me.YearAvail = Null

'keep the same doctor. go to the doctor field
Me.DoctorID.SetFocus
End Sub

I would probably have a routine that once a doctorID and Year is
entered to see if the record exists and set the Selected property to
true so you can see what has already been selected. I've provided
enough code for you to see how that can be done. Instead of looping
through the list of ItemsSeleted, you would do a loop using
For I = 0 TO Me.ListMOn.ListCount -1
...set month to true or false for existing records
Next
Nov 12 '05 #2

P: n/a
Ellen Manning wrote:
I'm developing an A2K adp that contains doctor info and the months
they are not available for teaching. A doctor can be unavailable for
some months for one year and other months for another year. I want
the user to enter the year then use a multi-select list box to choose
the months not available, then go to a fresh screen, enter another
year and choose the months not available for that year, and so on. In
the table, there is one record per year/month per doctor.

I've got the form set up and I can enter one year and the months but
can't figure out how to navigate to a fresh screen and enter the next
year. Maybe using a multi-select listbox isn't the way to go??? Any
ideas? Thanks.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The list box method of selecting months is OK, but you have to know that
all the selected values (records) will have to be written to the table
one-at-a-time. You can use a stored procedure (SP) & VBA code. Example
of the SP:

CREATE PROCEDURE usp_AddDoctorUnavailable
- -- If the DoctorNotAvailable table has more than these columns
- -- you will have to adjust the SP & the VBA code to insert those
- -- columns.

@DoctorID INTEGER ,
@Month DATETIME -- Format YYYYMM01

AS

INSERT INTO DoctorNotAvailable (DoctorID, Month)
VALUES (@DoctorID, @Month)

====

There should be a CommandButton on the form that saves the data to the
table "DoctorNotAvailable" (use the real table's name). E.g.
(untested):

Private Sub cmdSave_Click()
' In:
' Me!lstMonths The months to save
' Me!txtDoctorID The doctor's ID
' Me!txtYear The year the months are in
'

Dim cn As New ADODB.Connection
Dim strSQL As String
Dim strExec As String
Dim varRow as Variant

On Error GoTo err_

cn.Connection = CurrentProject.Connection
cn.Open

strSQL = "EXEC usp_AddDoctorUnavailable " & Me!txtDoctorID & ", "

' Assumes the list box's bound column returns the month number,
' and that txtYear holds a 4-digit year.
For Each varRow In Me!lstMonths.ItemsSelected
With Me!lstMonths
' Format the date to "YYYYMM01" & attach to EXEC statement.
' Note: single quotes have to surround the date value.
strExec = strSQL & " '" & Me!txtYear & _
Format(.ItemData(varRow),"00") & "01'"
cn.Execute strExec,,adCmdText
End With
Next varRow

' If reached here - success!
' Clear the selected values from the list box
' to show the user that the info was saved.
' Or show a MsgBox saying saved.
With Me!lstMonths
For Each varRow In .ItemsSelected
.Selected(varRow) = False
Next varRow
End With

exit_:
cn.Close
Set cn = Nothing
Exit Sub

err_:
' You may want to check for duplicates & just Resume Next
' instead of running the MsgBox.
MsgBox "An error occurred while saving the Doctor's " & _
"Unavailable months" & vbcr & vbcr & "Error: " & _
err.Description, vbCritical
Resume exit_

End Sub

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQH2udYechKqOuFEgEQK7ygCgkHfBI/HrAT4myW0qLQ50aeXwuOgAoLeY
rE92g44aXedjv2946IxhwxIY
=kzJ9
-----END PGP SIGNATURE-----

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.