Results 1 to 5 of 5
  1. #1
    Comtech is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    19

    Type Conversion Error in Update Query

    Hi again,

    I kinda posted this before, and I thought I had found a solution, but it turns out I was wrong. I have a form with 2 subforms. I'm trying to calculate attendance percentages for a cadet corps. When I open the form, I get the following error.
    Click image for larger version. 

Name:	Screenshot (1).png 
Views:	13 
Size:	12.5 KB 
ID:	29351

    If I click No, it points to the DoCmd.OpenQuery ("QueryUpdateAttendancePercentageCadets")



    Here is the code:

    Private Sub Form_Open(Cancel As Integer)


    On Error GoTo Err_Form_Open


    Dim CountCadets As Long
    Dim CountList As Long
    Dim nbrCadetsPresent As Long
    Dim nbrCadetsatTime As Long
    Dim nbrOfficersPresent As Long
    Dim nbrOfficersatTime As Long
    Dim dbTraining As Object
    Dim rstPresent As Recordset
    Dim AttCadetAverage As Long
    Dim strCadetAverage As String

    Set dbTraining = CurrentDb
    Set rstPresent = dbTraining.OpenRecordset("tblListofActivities")


    CountList = DCount("[ActivityID]", "tblListofActivities")
    CountCadets = DCount("[RecordID]", "tblCadetMain")


    Select Case CountCadets


    Case Is > 0


    [Forms]![frmAttendance]![sfrmAttendanceCadets].SetFocus
    DoCmd.GoToRecord , , acFirst


    For I = 1 To CountList
    nbrCadetsatTime = DCount("[RecordID]", "tblActivitiesCadets", "[ActivityID] =" & [Forms]![frmAttendance]![sfrmAttendanceCadets].[Form].ActivityID)
    nbrCadetsPresent = DCount("[RecordID]", "tblActivitiesCadets", "[ActivityID] =" & [Forms]![frmAttendance]![sfrmAttendanceCadets].[Form].ActivityID & "AND [Present]=True")
    rstPresent.Edit:
    If nbrCadetsatTime = 0 Then
    rstPresent("CadetsPresent").Value = 0:
    rstPresent("CadetCountatTime").Value = 0
    Else
    rstPresent("CadetsPresent").Value = nbrCadetsPresent:
    rstPresent("CadetCountatTime").Value = nbrCadetsatTime
    End If
    DoCmd.OpenQuery ("QueryUpdateAttendancePercentageCadets")
    rstPresent.Update:
    If I <> CountList Then
    rstPresent.MoveNext
    DoCmd.GoToRecord , , acNext
    End If
    Next I


    DoCmd.GoToRecord , , acFirst


    [Forms]![frmAttendance]![sfrmAttendanceOfficers].SetFocus
    DoCmd.GoToRecord , , acFirst


    For I = 1 To CountList
    nbrOfficersatTime = DCount("[RecordID]", "tblActivitiesOfficers", "[ActivityID] =" & [Forms]![frmAttendance]![sfrmAttendanceOfficers].[Form].ActivityID)
    nbrOfficersPresent = DCount("[RecordID]", "tblActivitiesOfficers", "[ActivityID] =" & [Forms]![frmAttendance]![sfrmAttendanceOfficers].[Form].ActivityID & "AND [Present]=True")
    rstPresent.Edit:
    If nbrOfficersatTime = 0 Then
    rstPresent("OfficersPresent").Value = 0:
    rstPresent("OfficerCountatTime").Value = 0
    Else
    rstPresent("OfficersPresent").Value = nbrOfficersPresent:
    rstPresent("OfficerCountatTime").Value = nbrOfficersatTime
    End If
    DoCmd.OpenQuery ("QueryUpdateAttendancePercentageOfficers")
    rstPresent.Update:
    If I <> CountList Then
    rstPresent.MoveNext
    DoCmd.GoToRecord , , acNext
    End If
    Next I


    DoCmd.GoToRecord , , acFirst


    End Select


    Exit_Form_Open:
    Exit Sub


    Err_Form_Open:
    MsgBox Err.Description
    Resume Exit_Form_Open


    End Sub


    The SQL for the "QueryUpdateAttendancePercentageCadets" is:

    UPDATE tblListofActivities INNER JOIN tblActivitiesCadets ON tblListofActivities.ActivityID = tblActivitiesCadets.ActivityID SET tblListofActivities.CadetAverage = Round([tblListofActivities].[CadetsPresent]/[tblListofActivities].[CadetCountatTime],2)*"100";

    The SQL for the "QueryUpdateAttendancePercentageOfficers" is:

    UPDATE tblListofActivities INNER JOIN tblActivitiesCadets ON tblListofActivities.ActivityID = tblActivitiesCadets.ActivityID SET tblListofActivities.OfficerAverage = Round([tblListofActivities].[OfficersPresent]/[tblListofActivities].[OfficerCountatTime],2)*"100";



    I have been working on this for this for several days, and any help would be greatly appreciated. Thank you.
    Comtech

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Code:
    vities].[CadetCountatTime],2)*"100";
    Maybe can't multiply by a string. Try:
    Code:
    vities].[CadetCountatTime],2) * 100;

  3. #3
    Comtech is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    19
    Thanks for the reply. I made the change, but it still doesn't work. Any other ideas?

    Comtech

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Take a closer look at your error message. The problem is not Type Conversion, It's Record Lock. The query is trying up update a table (tblListOfActivities) that's open as a recordset.
    Instead of using the update query, maybe you could update like:
    Code:
    rstPresent("CadetAverage")  = nbrCadetsPresent / nbrCadetsAtTime * 100

  5. #5
    Comtech is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    19
    I actually tried that first. But I got it working using just the query. Thank you for your help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 11-11-2013, 12:39 AM
  2. Replies: 8
    Last Post: 08-09-2012, 07:04 PM
  3. Type conversion error
    By corymw in forum Access
    Replies: 1
    Last Post: 07-25-2012, 11:55 AM
  4. Replies: 6
    Last Post: 06-14-2012, 03:39 PM
  5. Data Type Conversion Error
    By graviz in forum Forms
    Replies: 7
    Last Post: 06-04-2012, 11:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums