Select an existing batch number



I have tried looking though out the forums for a way to select a batch number to use when trying to import invoices into Sage 100. What I have found was to use SelectBatch and pass the batch number I want to use as the parameter, but when I do I keep getting the error "<batch_no> already exists". Below is a snippit of the code I'm using in C# with Dispatch Object

DispatchObject pvx = new DispatchObject("ProvideX.Script");
DispatchObject oSS = new DispatchObject(pvx.InvokeMethod("NewObject", "SY_Session"));
string[] login = readProfileFromDisk();
object success = oSS.InvokeMethod("nSetUser", login[0], login[1]);

oSS.InvokeMethod("nSetCompany", ControllerConfiguration.HostCompanyCode);
oSS.InvokeMethod("nSetDate", "A/R", DateTime.Today.ToString("yyyyMMdd"));
oSS.InvokeMethod("nSetModule", "A/R");

int apInvoiceTaskID = (int)oSS.InvokeMethod("nLookupTask", "SO_Invoice_ui");
oSS.InvokeMethod("nSetProgram", apInvoiceTaskID);
DispatchObject invoice = new DispatchObject(pvx.InvokeMethod("NewObject", "SO_Invoice_bus", oSS.GetObject()));

string batchNo = "5000";
//Fails Here
result = (int)invoice.InvokeMethod("nSelectBatch", batchNo);
if (result != 1) {
string message = invoice.InvokeMethod("sLastErrorMsg").ToString();

If batch 5000 doesn't exists, it creates a new batch fine in Sage 100 and everything works fine. Imports the invoice no problem.
But if I want to select the existing batch number 5000, I get the error "5000 already exists". If I try to ignore this message in case its actually just a warning and continue trying to import the invoice, after invoice.InvokeMethod("nSetKey") is called I get the error "A batch number is not set up." So I can assume here that it really did fail to set the Batch No. After that, get random error messages for nSetValue, most common being "Missing record to calculate taxes" and "You cannot use a credit card payment when credit card payment type is not set up." Ending with "This Invoice has no lines and has zero total amounts" after invoice.InvokeMethod("nWrite"), and yes I do add lines to the invoice.

If I change my batch number from 5000 to another number and try again, the invoice will import fine with none of the error messages above. Is there something I'm missing or are we not allowed to choose existing batch numbers when importing to SO_Invoice_ui?