Quote Originally Posted by coccoster View Post
Yep ive had Option Strict on the whole time.
I'm currently using vs2010.

Well with my code looking like:
vb Code:
  1. Public Sub g_sSaveCustomerRecord(ByVal oThisFormA As frmCaptureCustomer, _
  2.                                    ByVal sCusID As String, _
  3.                                    ByVal sDBNameA As String)
  4.         ' ---------------------------------------------------------------------
  5.         ' Incoming Parameters:
  6.         '       oThisFormA  - a reference to the current form
  7.         '                     of type frmDataCapture
  8.         '       sStudentNumberA - The student number
  9.         '       sDBNameA    - The Database File Name
  10.         ' Return value :
  11.         '       if save successfull (no validation issues) return empty string, ""
  12.         '       otherwise return error message
  13.         '------------------------------------------------------------
  14.         Dim sSaveSql As String
  15.         Dim sConnection As String
  16.         Dim sErrorMessage As String
  17.         Dim sSQL As String
  18.         Dim bStudentNumberExists As Boolean
  19.  
  20.         Dim oConn As OleDbConnection        'To reference a Connection obj.
  21.         Dim oCmd_Select As OleDbCommand     'To Instantiate a Command obj used to execute the Select SQL.
  22.         Dim oDataReader As OleDbDataReader  'To instantiate a DataReader obj.
  23.         Dim oCmd_Update As OleDbCommand     'To Instantiate a Command obj used to execute the Insert/Update SQL.
  24.  
  25.         'sErrorMessage = ""
  26.         oConn = Nothing
  27.         oCmd_Select = Nothing
  28.         oDataReader = Nothing
  29.         oCmd_Update = Nothing
  30.  
  31.         ' --- create a database command object and set the SQL statement
  32.         ' --- it will execute, and the database connection object associated to it
  33.         sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;"
  34.         sConnection = sConnection & "User ID=Admin;"
  35.         sConnection = sConnection & "Data Source="
  36.         sConnection = sConnection & Application.StartupPath & "\" & sDBNameA
  37.         oConn = New OleDbConnection(sConnection)
  38.         oConn.Open()
  39.  
  40.         oCmd_Select = oConn.CreateCommand()
  41.         sSQL = <SQL>select ID from CUSTOMER where ID= <%= sCusID %></SQL>.Value
  42.         'sSQL = "select ID from CUSTOMER where ID= " & sCusID & ""
  43.         oCmd_Select.CommandText = sSQL
  44.  
  45.         ' --- execute SQL command and place results into a datareader object
  46.         oDataReader = oCmd_Select.ExecuteReader()
  47.  
  48.         bStudentNumberExists = (oDataReader.Read() = True)
  49.  
  50.  
  51.         ' --- Build Insert or Update Sql depending if record retrieved with select query is found
  52.         If bStudentNumberExists Then
  53.  
  54.             If bStudentNumberExists Then
  55.  
  56.                 Using cmd As OleDbCommand = New OleDbCommand
  57.                     cmd.CommandText = _
  58.                     <SQL>
  59.                 UPDATE CUSTOMER set
  60.                     Surname = ?,
  61.                     Given = ?,
  62.                     DateOfBirth = ?,
  63.                     Sex = ?,
  64.                     Phone = ?,
  65.                     Address = ?,
  66.                     Suburb = ?,
  67.                     State = ?,
  68.                     PostCode = ?
  69.                 WHERE ID = ?
  70.                 </SQL>.Value
  71.  
  72.  
  73.                     cmd.Parameters.AddWithValue("@Surname", oThisFormA.txtCusSurname.Text.Trim)
  74.                     cmd.Parameters.AddWithValue("@Given", oThisFormA.txtCustGiven.Text.Trim)
  75.                     cmd.Parameters.AddWithValue("@DateOfBirth", CDate(oThisFormA.txtCustDOB.Text.Trim))
  76.                     cmd.Parameters.AddWithValue("@Sex", oThisFormA.txtCustSex.Text.Trim)
  77.                     cmd.Parameters.AddWithValue("@Phone", oThisFormA.txtCustPhone.Text.Trim)
  78.                     cmd.Parameters.AddWithValue("@Address", oThisFormA.txtCustAddress.Text.Trim)
  79.                     cmd.Parameters.AddWithValue("@Suburb", oThisFormA.txtCustSuburb.Text.Trim)
  80.                     cmd.Parameters.AddWithValue("@State", oThisFormA.txtCustState.Text.Trim)
  81.                     cmd.Parameters.AddWithValue("@PostCode", oThisFormA.txtCustPostCode.Text.Trim)
  82.                     cmd.Parameters.AddWithValue("@ID", CInt(oThisFormA.txtCustID.Text.Trim))
  83.  
  84.  
  85.                 End Using
  86.  
  87.             End If
  88.  
  89.  
  90.             '    ' Be careful however with the commas and the closing bracket
  91.         End If
  92.  
  93.  
  94.         oDataReader.Close()
  95.         oCmd_Select.Dispose()
  96.  
  97.  
  98.         ' Execute sql update or insert query:
  99.         oCmd_Update = oConn.CreateCommand()
  100.         oCmd_Update.CommandText = sSaveSql
  101.         oCmd_Update.ExecuteNonQuery()
  102.  
  103.     End Sub

I am getting the same
Code:
"Command text was not set for the command object."
error

I put Option Infer On right at the top aswell.
Which line number in regards to the code above is giving you this error message.