Why doesn't this button work? 
Author Message
 Why doesn't this button work?

I can't get the following code to work.  It is attached to the click event
on a button on a subform.  The button is in the form footer.  It goes
through to see which consultants have a check in the checkbox next to their
name.  If so, it is suppose to take them out of the "bullpen" and staff them
on the project.  So, it deletes them from the "bullpen" table and adds them
to the "staffed" table.  I'm sorry the code doesn't follow naming
conventions, I picked it up from someone else.  Anyway, when I click the
button NOTHING happens except the screen refreshes.  Any help you can answer
me here, or better yet e-mail me because I'll get it faster.

Thank you.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''

Private Sub btnHeresTeam_Click()

Dim dbs As Database
Dim rec As Recordset
Dim Value1 As String
Dim Value2 As String
Dim Value3 As String
Dim Value4 As Date
Dim Value5 As Date

'ID number of project
Value1 = [Forms]![test -staffing]![PCode]
'ID number of consultant
Value2 = Forms![test -staffing]![bullpen subform].Form![IDNumb]
'Utilization needed for project
Value3 = Forms![test -staffing]![bullpen subform].Form![Utilization]
'Start date of project
Value4 = Forms![test -staffing]![bullpen subform].Form![Start]
'End date of project
Value5 = Forms![test -staffing]![bullpen subform].Form![End]

Set dbs = CurrentDb
Set rec = dbs.OpenRecordset("qryStaffedBullpen")

Do Until rec.EOF

    'If the checkbox is checked then...
    If Forms![test -staffing]![bullpen subform].Form![Team_C] = True Then

        'Runs an append query that inserts the selected values from the
        '   bullpen subform to the staffed table
        dbs.Execute "INSERT INTO staffed " _
             & "(Project_ID, idnumb, Utilization, start,end) VALUES " _
             & "('" & Value1 & "','" & Value2 & "','" & Value3 & "','" &
Value4 & "','" & Value5 & "');"

        'Runs an update query that subtracts the utilization required for
the proj.
        '   from the staff members avail. utilization.
        dbs.Execute "UPDATE people SET Utilization_f = utilization_f - '" &
Value3 & "' WHERE idnumb = '" & Value2 & "'"

    End If

    rec.MoveNext

  Loop

dbs.close
Forms("Test -Staffing").Requery  'Refreshes the screen

End Sub



Fri, 29 Nov 2002 03:00:00 GMT  
 Why doesn't this button work?
Cindy,

Without studying all your code, I suggest you add the optional parameter dbFailOnError to your dbs.Execute statements.

As in:

dbs.Execute "UPDATE people SET Utilization_f = utilization_f - '" &
Value3 & "' WHERE idnumb = '" & Value2 & "'", dbFailOnError

If you read up on the Execute method in Help, you'll find that it will fail silently... not very helpful.

I suspect one of your values in the INSERT or UPDATE queries are not properly deliminated (looks like you're
missing #'s around start and end for starters).

Steve

Quote:

> I can't get the following code to work.  It is attached to the click event
> on a button on a subform.  The button is in the form footer.  It goes
> through to see which consultants have a check in the checkbox next to their
> name.  If so, it is suppose to take them out of the "bullpen" and staff them
> on the project.  So, it deletes them from the "bullpen" table and adds them
> to the "staffed" table.  I'm sorry the code doesn't follow naming
> conventions, I picked it up from someone else.  Anyway, when I click the
> button NOTHING happens except the screen refreshes.  Any help you can answer
> me here, or better yet e-mail me because I'll get it faster.

> Thank you.

> ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
> ''''''''''''''''''''''''''''''''''''''''''''''

> Private Sub btnHeresTeam_Click()

> Dim dbs As Database
> Dim rec As Recordset
> Dim Value1 As String
> Dim Value2 As String
> Dim Value3 As String
> Dim Value4 As Date
> Dim Value5 As Date

> 'ID number of project
> Value1 = [Forms]![test -staffing]![PCode]
> 'ID number of consultant
> Value2 = Forms![test -staffing]![bullpen subform].Form![IDNumb]
> 'Utilization needed for project
> Value3 = Forms![test -staffing]![bullpen subform].Form![Utilization]
> 'Start date of project
> Value4 = Forms![test -staffing]![bullpen subform].Form![Start]
> 'End date of project
> Value5 = Forms![test -staffing]![bullpen subform].Form![End]

> Set dbs = CurrentDb
> Set rec = dbs.OpenRecordset("qryStaffedBullpen")

> Do Until rec.EOF

>     'If the checkbox is checked then...
>     If Forms![test -staffing]![bullpen subform].Form![Team_C] = True Then

>         'Runs an append query that inserts the selected values from the
>         '   bullpen subform to the staffed table
>         dbs.Execute "INSERT INTO staffed " _
>              & "(Project_ID, idnumb, Utilization, start,end) VALUES " _
>              & "('" & Value1 & "','" & Value2 & "','" & Value3 & "','" &
> Value4 & "','" & Value5 & "');"

>         'Runs an update query that subtracts the utilization required for
> the proj.
>         '   from the staff members avail. utilization.
>         dbs.Execute "UPDATE people SET Utilization_f = utilization_f - '" &
> Value3 & "' WHERE idnumb = '" & Value2 & "'"

>     End If

>     rec.MoveNext

>   Loop

> dbs.close
> Forms("Test -Staffing").Requery  'Refreshes the screen

> End Sub



Fri, 29 Nov 2002 03:00:00 GMT  
 Why doesn't this button work?
I corrected some of the relationships in my tables and now when I click the
button it posts the first record to the staffed table 80 times.  Does anyone
know what's going on??


Quote:
> I can't get the following code to work.  It is attached to the click event
> on a button on a subform.  The button is in the form footer.  It goes
> through to see which consultants have a check in the checkbox next to
their
> name.  If so, it is suppose to take them out of the "bullpen" and staff
them
> on the project.  So, it deletes them from the "bullpen" table and adds
them
> to the "staffed" table.  I'm sorry the code doesn't follow naming
> conventions, I picked it up from someone else.  Anyway, when I click the
> button NOTHING happens except the screen refreshes.  Any help you can
answer
> me here, or better yet e-mail me because I'll get it faster.

> Thank you.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

- Show quoted text -

Quote:
> ''''''''''''''''''''''''''''''''''''''''''''''

> Private Sub btnHeresTeam_Click()

> Dim dbs As Database
> Dim rec As Recordset
> Dim Value1 As String
> Dim Value2 As String
> Dim Value3 As String
> Dim Value4 As Date
> Dim Value5 As Date

> 'ID number of project
> Value1 = [Forms]![test -staffing]![PCode]
> 'ID number of consultant
> Value2 = Forms![test -staffing]![bullpen subform].Form![IDNumb]
> 'Utilization needed for project
> Value3 = Forms![test -staffing]![bullpen subform].Form![Utilization]
> 'Start date of project
> Value4 = Forms![test -staffing]![bullpen subform].Form![Start]
> 'End date of project
> Value5 = Forms![test -staffing]![bullpen subform].Form![End]

> Set dbs = CurrentDb
> Set rec = dbs.OpenRecordset("qryStaffedBullpen")

> Do Until rec.EOF

>     'If the checkbox is checked then...
>     If Forms![test -staffing]![bullpen subform].Form![Team_C] = True Then

>         'Runs an append query that inserts the selected values from the
>         '   bullpen subform to the staffed table
>         dbs.Execute "INSERT INTO staffed " _
>              & "(Project_ID, idnumb, Utilization, start,end) VALUES " _
>              & "('" & Value1 & "','" & Value2 & "','" & Value3 & "','" &
> Value4 & "','" & Value5 & "');"

>         'Runs an update query that subtracts the utilization required for
> the proj.
>         '   from the staff members avail. utilization.
>         dbs.Execute "UPDATE people SET Utilization_f = utilization_f - '"
&
> Value3 & "' WHERE idnumb = '" & Value2 & "'"

>     End If

>     rec.MoveNext

>   Loop

> dbs.close
> Forms("Test -Staffing").Requery  'Refreshes the screen

> End Sub



Sat, 30 Nov 2002 03:00:00 GMT  
 Why doesn't this button work?
Hi Cindy,
Well, you're looping through the recordset and on each pass the code checks
weather or not the check box on your form is checked! If it is, the append query

is run. So the query gets run for every record in your recordset.
I think you probably want to check that yes/no field in each record in the
table itself, not the check box on the form. Also the values you are inserting
are always from that one record that your form is displaying.

So you want to loop through the recordset, checking your yes/no field,
if it is yes, then add that record to your table while deleting it from the
Bullpen.
hth
Dan

Quote:

> I corrected some of the relationships in my tables and now when I click the
> button it posts the first record to the staffed table 80 times.  Does anyone
> know what's going on??



> > I can't get the following code to work.  It is attached to the click event
> > on a button on a subform.  The button is in the form footer.  It goes
> > through to see which consultants have a check in the checkbox next to
> their
> > name.  If so, it is suppose to take them out of the "bullpen" and staff
> them
> > on the project.  So, it deletes them from the "bullpen" table and adds
> them
> > to the "staffed" table.  I'm sorry the code doesn't follow naming
> > conventions, I picked it up from someone else.  Anyway, when I click the
> > button NOTHING happens except the screen refreshes.  Any help you can
> answer
> > me here, or better yet e-mail me because I'll get it faster.

> > Thank you.

> ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
> > ''''''''''''''''''''''''''''''''''''''''''''''

> > Private Sub btnHeresTeam_Click()

> > Dim dbs As Database
> > Dim rec As Recordset
> > Dim Value1 As String
> > Dim Value2 As String
> > Dim Value3 As String
> > Dim Value4 As Date
> > Dim Value5 As Date

> > 'ID number of project
> > Value1 = [Forms]![test -staffing]![PCode]
> > 'ID number of consultant
> > Value2 = Forms![test -staffing]![bullpen subform].Form![IDNumb]
> > 'Utilization needed for project
> > Value3 = Forms![test -staffing]![bullpen subform].Form![Utilization]
> > 'Start date of project
> > Value4 = Forms![test -staffing]![bullpen subform].Form![Start]
> > 'End date of project
> > Value5 = Forms![test -staffing]![bullpen subform].Form![End]

> > Set dbs = CurrentDb
> > Set rec = dbs.OpenRecordset("qryStaffedBullpen")

> > Do Until rec.EOF

> >     'If the checkbox is checked then...
> >     If Forms![test -staffing]![bullpen subform].Form![Team_C] = True Then

> >         'Runs an append query that inserts the selected values from the
> >         '   bullpen subform to the staffed table
> >         dbs.Execute "INSERT INTO staffed " _
> >              & "(Project_ID, idnumb, Utilization, start,end) VALUES " _
> >              & "('" & Value1 & "','" & Value2 & "','" & Value3 & "','" &
> > Value4 & "','" & Value5 & "');"

> >         'Runs an update query that subtracts the utilization required for
> > the proj.
> >         '   from the staff members avail. utilization.
> >         dbs.Execute "UPDATE people SET Utilization_f = utilization_f - '"
> &
> > Value3 & "' WHERE idnumb = '" & Value2 & "'"

> >     End If

> >     rec.MoveNext

> >   Loop

> > dbs.close
> > Forms("Test -Staffing").Requery  'Refreshes the screen

> > End Sub



Mon, 02 Dec 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Why oh why doesn't this work?

2. Why LoadPicture() works on local pathes and doesn't work on the URLS

3. ActiveX-Exe: .Value=True doesn't work while direct click on button works

4. Why doesn't Mouse Button 2 return a List Index

5. Code doesn't work, why?

6. Why doesn't this MAPISendMail work?

7. SQL in VB doesn't work - why?

8. Why doesn't this work?

9. Why doesn't this work???

10. Why doesn't this work?!!

11. Why doesn't this work?

12. why this code doesn't work?

 

 
Powered by phpBB® Forum Software