Office Systems Developer

Joao Livio (Portugal)

VSTO (Access) – Convert a Field to Upper, Lower, Proper

public string ConvertFieldToUpper(string MyTable, string MyField)
{
Access.Application oAccess = ((Access.Application)
(Marshal.GetActiveObject("Access.Application")));
try
{
string strSQL;
strSQL = String.Format("UPDATE {0} SET {1} = UCase([{1}])", MyTable, MyField);

oAccess.DoCmd.RunSQL(strSQL.ToString(),null);
return "OK";
}
catch (Exception)
{
throw;
}
finally
{
Marshal.ReleaseComObject(oAccess);
}
}


public string ConvertFieldToLower(string MyTable, string MyField)
{
Access.Application oAccess = ((Access.Application)
(Marshal.GetActiveObject("Access.Application")));
try
{
string strSQL;
strSQL = String.Format("UPDATE {0} SET {1} = LCase([{1}])", MyTable, MyField);

oAccess.DoCmd.RunSQL(strSQL.ToString(), null);
return "OK";
}
catch (Exception)
{
throw;
}
finally
{
Marshal.ReleaseComObject(oAccess);
}
}


public string ConvertFieldToProper(string MyTable, string MyField)
{
Access.Application oAccess = ((Access.Application)
(Marshal.GetActiveObject("Access.Application")));
try
{
string strSQL;
strSQL = String.Format("UPDATE {0} SET {1} = STRCONV([{1},3])", MyTable, MyField);

oAccess.DoCmd.RunSQL(strSQL.ToString(), null);
return "OK";
}
catch (Exception)
{
throw;
}
finally
{
Marshal.ReleaseComObject(oAccess);
}
}

Leave a Comment

(required) 

(required) 

(optional)

(required)