title: Get Next Number MS Access
body: <p>I am trying to create a Work Order System for a company and I am limited to using MS Access. I am wanting to code in a Work Order ID column. This column will be based on 2 combobox options:</p>
  
  <p>BuildingName
  TargetDepartment</p>
  
  <p>I need some VBA code to query the WOID column in the table to retrieve the next number. The conditions will be as the below example:</p>
  
  <pre>WOID                BuildingName     TargetDepartment
  BUILDA-DEPTA-1      BUILDA           DEPTA
  BUILDA-DEPTB-1      BUILDA           DEPTB
  BUILDA-DEPTA-2      BUILDA           DEPTA
  </pre>
  
  <p>The VBA code would query the WOID column, and find out if there is a work order for the same building and department and then increment the number at the end by 1. But if there is no WOID that matches the buildingname and targetdepartment, it would create the first entry for that. </p>
  
  <p>So if it finds a matching buildingname and targetdepartment: MaxNumber +1
  If it doesn't find a matching buildingname and targetdepartment: 1</p>
  
  <p>Thanks for the help!</p>