Results 1 to 5 of 5

Thread: Criteria syntax for Access

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    24
    I am trying to use the DSUM function in Access. Here is the code as I currently have it.

    Private Sub Command0_Click()
    Dim rstUpdate As Recordset, dbs As Database
    Dim intWeek As Integer, intTotal As Integer
    Dim strLine As String
    Set dbs = CurrentDb
    Set rstUpdate = dbs.OpenRecordset("USED", dbOpenTable)
    With rstUpdate
    .MoveFirst
    Do While Not .EOF
    intWeek = !week
    strLine = !Line
    intTotal = DSum("[MIS]+[pty]", "USED", "[WEEK] = " & intWeek And "[LINE] = " & strLine)
    .Edit
    !totalused = intTotal
    .Update
    .MoveNext
    Loop
    End With
    End Sub

    When I run the program, I get a run-time error '13' and it states there is a type mismatch. It highlights the line of code using the DSUM function. I'm sure it is due to the code involving ("[LINE] = " & strLine) because it will work it I take it out. But I have to use the line as part of the criteria in order to get the info I need. Anyone know how it should be written?

    Thanks,
    ern

  2. #2
    Fanatic Member HaxSoft's Avatar
    Join Date
    May 2000
    Location
    Ohio
    Posts
    593

    Lightbulb Quotes missing perhaps?

    Hi, is the strLine holding a textual value? If so, try changing this line:
    Code:
    intTotal = DSum("[MIS]+[pty]", "USED", "[WEEK] = " & intWeek And "[LINE] = " & strLine)
    to this instead:
    Code:
    intTotal = DSum("[MIS]+[pty]", "USED", "[WEEK] = " & intWeek And "[LINE] = '" & strLine & "'")
    Maybe you just forgot the quotes.

    Just a suggestion, hope it works.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    24
    strLine does hold a text value. Unfortunately, the change in code still causes a type mismatch error.

    I do appreciate your assistance.

    ern

  4. #4
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274

    Question Are you sure you don't want COUNT instead?

    Are you trying to get a sum from a text value? I thought you could only sum up numeric values (int, doubles, etc)

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    24
    I'm trying to find out the total qty of MIS + PTY (TotalUsed) by Week/Line. MIS and PTY are number of boxes being shipped. There are several different types of boxes. Here is an example of the USED table.

    Week Box Line Mis Pty TotalUsed
    1 blue 1 FCO 2 5
    1 blue 2 FCO 4 7
    1 blue 1 FFR 5 10
    1 blue 2 FFR 6 9

    In the above example, if the program was running correctly, I would end up with 18 as the TotalUsed for the first and second records and 30 as the TotalUsed for the third and fourth records.

    Hope this makes some sense.

    ern

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width