MS Access required field event procedure if another field contains a certain value

MatthewLane412

New Member
I am working on a split form in ms access. I would like my form to not add a record if the Sending_Category = Contractors or Salaries & Benefits, and the Sending_FTE is blank. I have tried this as an on click event for the "Add Record" Macro, and on the form as a before update event. My "add record" button stops adding records when I have this code inserted, and it doesn't work with the criteria. Any ideas? Thanks

Code:
If Me.Sending_Category = Contractors Then
                 If IsNull (Me.Sending_FTE) Then
                     MsgBox "You mut enter a sending FTE before this record can be saved"
                  Cancel = True
                  Me.Sending_FTE.SetFocus
               End If
Else
    'Do Nothing
EndIf
 

welshgasman

Well-known Member
Set a breakpoint in the event and walk through the code with F8.
Chances are Sending_FTE is not null.?

Perhaps use the NZ function?
Code:
If NZ(Me.Sending_FTE,"") = "" Then
HTH
 

welshgasman

Well-known Member
That is not a lot to go on? :(
What *exactly* did not work?, what were the values in the controls?
For a start you should be checking for "Contractors" as it is a string?
 
Last edited:

MatthewLane412

New Member
Sorry for the delayed response. I have figured out this much. If I type in 'Contractors' into the control source box. The code works. If I use the normal control source which pulls from another table (pasted from excel) the code doesn't work. Thanks.
 

welshgasman

Well-known Member
Still not a lot to go on.
However if this was my problem, I would walk through the code with F8 after setting a breakpoint.
From what you have no said, it appears that you are not really using Contractors in some way when you pull from a table.?

If that field is a Lookup field in the table, then it is not really Contractors, but the key for Contractors from wherever you get that data.?
 

Some videos you may like

This Week's Hot Topics

  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • find many based on a certain criteria
    good evening, I hope someone can help me? I have a workbook sheet 2 contains lots of data.... I would like to be able to find anything on sheet...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
  • Text Format
    I have a sheet for user to keyin the data. The format of the data can be 451 / 1903, 0012 / 9908 or 00287 / 0099. The number after the "/" is...
  • Syntax errors
    Good Morning, Trying to compile a workbook, I keep getting a few errors. Here are the first two: [code=rich]Syntax Error: Function...
Top