Results 1 to 7 of 7

Thread: Access required field

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374

    Unhappy

    Okay, here's the situation: I am using ADODC and Access 2000, and I need a certain field to be required only when a boolean value is true. I can't change the attributes of the table on the fly because it is a multi-user program. I have tried things such as
    Code:
    Private Sub Adodc1_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
    
    If Me.Visible = False Or MyBoolean = False Then Exit Sub
    
    If adReason = adRsnUpdate And dbcGroup = "" Then
        MsgBox "Must enter a group."
        dbcGroup.SetFocus    
        adStatus = adStatusCancel
    End If
    
    End Sub
    and I have tried putting similar code in the other events. All has been to no avail because everything gives me an error somewhere.

    Help?

  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Have you tried:

    [code]
    <font color="#00007F">If</font> adReason = adRsnUpdate then
    <font color="#00007F">If</font> len(dbcGroup) < 1 or <font color="#00007F">IsNull</font>(dbcGroup) <font color="#00007F">Then</font>
    MsgBox "Must enter a group."
    dbcGroup.SetFocus
    adStatus = adStatusCancel
    <font color="#00007F">End</font> <font color="#00007F">If</font>
    <font color="#00007F">End</font> <font color="#00007F">If</font>

    [\code]

  3. #3
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Appears to be a bug if you preview embeded code before posting. Response was supposed to be:


    [code]
    If adReason = adRsnUpdate then
    If len(dbcGroup) < 1 or IsNull(dbcGroup) Then
    MsgBox "Must enter a group."
    dbcGroup.SetFocus
    adStatus = adStatusCancel
    End If
    End If

    [\code]

    bug left for amdinistrators.

    Originally posted by JHausmann
    Have you tried:

    [code]
    <font color="#00007F">If</font> adReason = adRsnUpdate then
    <font color="#00007F">If</font> len(dbcGroup) < 1 or <font color="#00007F">IsNull</font>(dbcGroup) <font color="#00007F">Then</font>
    MsgBox "Must enter a group."
    dbcGroup.SetFocus
    adStatus = adStatusCancel
    <font color="#00007F">End</font> <font color="#00007F">If</font>
    <font color="#00007F">End</font> <font color="#00007F">If</font>

    [\code]

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374

    Unhappy

    Okay, that seems to work fairly well, but the only problem is that it cancels the entire transaction and the user has to fill in EVERY FIELD again. Any more tips?

  5. #5
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    If adReason = adRsnUpdate then
    If len(dbcGroup) < 1 or IsNull(dbcGroup) Then
    MsgBox "Must enter a group."
    dbcGroup.SetFocus
    End If
    End If

    put the above in the lost focus event for dbcgroup

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374

    Angry

    JHaussman thanks for trying to help, but with your last
    suggestion the error message shows and then the recordset
    moves anyway. I also tried saving the entered data into
    some variables, cancelling the transaction, adding a new
    record again, and pasting the saved values back into the
    recordset. But that makes the program crash

    Thanks again for trying, but I think I will quit this line
    of work before it stresses me to death. At least until
    9:00 tomorrow morning.

  7. #7
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Remove these two lines from your if condition that sets focus to the field:

    MsgBox "Must enter a group."
    adStatus = adStatusCancel

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