Results 1 to 8 of 8

Thread: Dcount (2k)

  1. #1
    2 Star Lounger
    Join Date
    Nov 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dcount (2k)

    My Quest in the Attch file.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Dcount (2k)

    Try the following code in the Before Insert event of the form:

    Private Sub Form_BeforeInsert(Cancel As Integer)
    If DCount("*", "tbl2") >= 50 Then
    MsgBox "Cannot add new record.", vbInformation
    Cancel = True
    End If
    End Sub

    It works in my own test database; I cannot test it in your database, probably because you use an Arabic language system.

  3. #3
    2 Star Lounger
    Join Date
    Nov 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dcount (2k)

    it works with me good. thank u hans
    Ashraf

  4. #4
    2 Star Lounger
    Join Date
    Nov 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dcount (2k)

    another idea ;
    i have tblBuss contain bus no - seats .
    bus no 1 has 5 seats
    bus no 2 has 8 seats
    i want to add that in the entry of the former form ( when the user enter bus no not allow 5 seats in tblbuss ) .
    Ashraf

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Dcount (2k)

    You will have to use the Before Update event of the text box, and set Cancel = True if the condition is not met.

    If you want more detailed help, you will have to provide more detailed information.

  6. #6
    2 Star Lounger
    Join Date
    Nov 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dcount (2k)

    ur code work already but now i have another modify .
    i create tbl called buss the 1st bus has 5 seat 2nd has 10 seat ...etc .
    i want when the user choose the bus no also clount the seats for evry bus and not allow more than the seats in tabl buss.
    ashraf

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Dcount (2k)

    Try this:
    <code>
    Private Sub bus_no_BeforeUpdate(Cancel As Integer)
    If DCount("*", "tbl2", "[bus no] = " & Chr(34) & Me.[bus no] & Chr(34)) >= _
    DLookup("Seats", "tblBuss", "[bus no] = " & Chr(34) & Me.[bus no] & Chr(34)) Then
    MsgBox "Cannot select this bus.", vbInformation
    Cancel = True
    End If
    End Sub</code>

  8. #8
    2 Star Lounger
    Join Date
    Nov 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dcount (2k)

    very good . thank u my dear .
    Ashraf

Posting Permissions

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