Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / July 2007

Tip: Looking for answers? Try searching our database.

Select All

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DS - 16 Jul 2007 01:28 GMT
This works fine if I select one or all, by clicking one by one.
I want that if nothing is selected then that means all are selected,
then the code runs for all records in the listbox.

Dim CashSQL As String
Dim varSelected As Variant
    DoCmd.SetWarnings False
    For Each varSelected In Me.ListEmp.ItemsSelected
      CASHSQL = "UPDATE tblEmployees " & _
         "SET tblEmployees.EmpCashedOut = -1 " & _
         "WHERE tblEmployees.EmployeeId = " & _
          Me.ListEmp.ItemData(varSelected)
       DoCmd.RunSQL (CASHSQL)
    Next

Any help appreciated,
Thanks,
DS
John W. Vinson - 16 Jul 2007 01:54 GMT
>This works fine if I select one or all, by clicking one by one.
>I want that if nothing is selected then that means all are selected,
>then the code runs for all records in the listbox.

Dim CashSQL As String
Dim varSelected As Variant
    DoCmd.SetWarnings False
    If Me.ListEmp.ItemsSelected.Count = 0 Then
       CASHSQL = "UPDATE tblEmployees " & )
          "SET tblEmployees.EmpCashedOut = -1"
    Else
      For Each varSelected In Me.ListEmp.ItemsSelected
         CASHSQL = "UPDATE tblEmployees " & _
            "SET tblEmployees.EmpCashedOut = -1 " & _
            "WHERE tblEmployees.EmployeeId = " & _
            Me.ListEmp.ItemData(varSelected)
      Next
    End If
    DoCmd.RunSQL (CASHSQL)

This will update all employees in the entire table - you'll need to add some
criteria (those from the listbox's rowsource) if that's not what you want.

            John W. Vinson [MVP]
DS - 16 Jul 2007 03:23 GMT
>>This works fine if I select one or all, by clicking one by one.
>>I want that if nothing is selected then that means all are selected,
[quoted text clipped - 20 lines]
>
>              John W. Vinson [MVP]
Hi John, Thank You.  It does update the entire table....but just how do
I do just the Employees that are in the listbox since I'm not selecting
any employees in the listbox...

Thanks
DS
John W. Vinson - 16 Jul 2007 06:55 GMT
>> This will update all employees in the entire table - you'll need to add some
>> criteria (those from the listbox's rowsource) if that's not what you want.
[quoted text clipped - 3 lines]
>I do just the Employees that are in the listbox since I'm not selecting
>any employees in the listbox...

Since I don't know how your listbox limits the employees (presumably a query?)
all I can do is repeat the advice above. Take a look at your listbox's
RowSource query and replicate it in the SQL string of the "null" branch.

            John W. Vinson [MVP]
DS - 16 Jul 2007 14:06 GMT
>>>This will update all employees in the entire table - you'll need to add some
>>>criteria (those from the listbox's rowsource) if that's not what you want.
[quoted text clipped - 10 lines]
>
>              John W. Vinson [MVP]
Thanks John I should have pasted the rowsource code...I tried taking
your advice but alas I am still coming up short on the solution...here
is the code...
Thanks
DS

With Me.ListEmp
.RowSource = "SELECT tblEmployees.EmployeeID, [EmpFirstName] & "" "" &
[EmpLastName] AS EMP, " & _
"tblEmployees.EmpSignedIN, tblEmployees.EmpCashedOut " & _
"FROM tblEmployees " & _
"WHERE (((tblEmployees.EmployeeID) Not In (SELECT tblChecks.ChkServer " & _
"FROM tblChecks INNER JOIN tblEmployees ON tblChecks.ChkServer =
tblEmployees.EmployeeID " & _
"WHERE (((tblChecks.ChkCancelled) = 0) " & _
"And ((tblChecks.ChkPaid) = 0) " & _
"And ((tblEmployees.EmpSignedIN) = -1) " & _
"And ((tblEmployees.EmpCashedOut) = 0)) " & _
"ORDER BY [EmpFirstName] & "" "" & [EmpLastName])) " & _
"AND ((tblEmployees.EmpSignedIN)=-1) " & _
"AND ((tblEmployees.EmpCashedOut)=0));"
.ColumnCount = 4
.ColumnWidths = "0 in;2 in;0 in;0 in"
.Requery
End With
John W. Vinson - 17 Jul 2007 01:45 GMT
>>>>This will update all employees in the entire table - you'll need to add some
>>>>criteria (those from the listbox's rowsource) if that's not what you want.
[quoted text clipped - 35 lines]
>.Requery
>End With

That's complex enough that I'd suggest making it a stored Query and using that
query in your code (rather than the tablename).

            John W. Vinson [MVP]
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.