M
mack225
Guest
Hi,
I'm, getting an error when I run the following code, only on some records though (the same ones).
The code is used to take a result from a combo box, take the primary key from the combo selection, and use this to find a single record from the database. The the form displays this via textboxes set up for this purpose (prefixed with txt in the form code). It gernally does this successfully with most records, no problem, but some records throw up the following:
Run time error 2147352567 (80020009)
The value you entered isn't valid for this field
Code as below, error is highlighted in the debugger on the first textbox assignment (when I deleted this, it went on to throw the error up on the next textbox assignment in the code!):
Private Sub cmbClient_AfterUpdate()
Dim cmbString As String
Dim intStrLength As Integer
Dim intStart As Integer
Dim mySQL As String
Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim myRecordSet As New ADODB.Recordset
myRecordSet.ActiveConnection = cnn1
myRecordSet.CursorType = adOpenKeyset
myRecordSet.LockType = adLockOptimistic
cmbString = cmbClient.Value
intStrLength = Len(cmbString)
intStart = InStr(1, cmbString, "*")
intStart = intStart + 1
cmbString = Mid(cmbString, intStart)
Debug.Print cmbString
mySQL = "SELECT TblCOMPANY.*, TblCONTACT.* " _
& "FROM TblCOMPANY INNER JOIN TblCONTACT ON TblCOMPANY.CompanyID = TblCONTACT.CompanyID " _
& "WHERE (((TblCONTACT.CompanyID)=" & cmbString & "))"
myRecordSet.Open mySQL
txtTitle = myRecordSet("Title")
txtForename2 = myRecordSet("forename")
txtSurname2 = myRecordSet("surname")
txtPosition = myRecordSet("position")
txtDept = myRecordSet("Dept")
txtTelNo = myRecordSet("TelephoneNo")
txtMobNo = myRecordSet("MobilePhone")
txtHomeNo = myRecordSet("HomeTelNo")
txtFaxNo = myRecordSet("faxnumber")
'txtURL = myRecordSet("URL")
txtemail1 = myRecordSet("email1")
txtemail2 = myRecordSet("email2")
'txtsource = myRecordSet("source")
txtsms = myRecordSet("sms")
txtBusName = myRecordSet("BusinessName")
txtBusType = myRecordSet("BusinessType")
txtAdd1 = myRecordSet("address1")
txtAdd2 = myRecordSet("address2")
txtadd3 = myRecordSet("address3")
txtAdd4 = myRecordSet("address4")
txtTownCity = myRecordSet("TownCity")
txtRegion = myRecordSet("Region")
txtPostcode2 = myRecordSet("Postcode")
txtEmployeeNo = myRecordSet("EmployeeNo")
txtSIC = myRecordSet("SIC")
txtSICDescription = myRecordSet("SICCategory")
txtTurnover = myRecordSet("Turnover")
Set myRecordSet = Nothing
Set cnn1 = Nothing
End Sub
I'm, getting an error when I run the following code, only on some records though (the same ones).
The code is used to take a result from a combo box, take the primary key from the combo selection, and use this to find a single record from the database. The the form displays this via textboxes set up for this purpose (prefixed with txt in the form code). It gernally does this successfully with most records, no problem, but some records throw up the following:
Run time error 2147352567 (80020009)
The value you entered isn't valid for this field
Code as below, error is highlighted in the debugger on the first textbox assignment (when I deleted this, it went on to throw the error up on the next textbox assignment in the code!):
Private Sub cmbClient_AfterUpdate()
Dim cmbString As String
Dim intStrLength As Integer
Dim intStart As Integer
Dim mySQL As String
Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim myRecordSet As New ADODB.Recordset
myRecordSet.ActiveConnection = cnn1
myRecordSet.CursorType = adOpenKeyset
myRecordSet.LockType = adLockOptimistic
cmbString = cmbClient.Value
intStrLength = Len(cmbString)
intStart = InStr(1, cmbString, "*")
intStart = intStart + 1
cmbString = Mid(cmbString, intStart)
Debug.Print cmbString
mySQL = "SELECT TblCOMPANY.*, TblCONTACT.* " _
& "FROM TblCOMPANY INNER JOIN TblCONTACT ON TblCOMPANY.CompanyID = TblCONTACT.CompanyID " _
& "WHERE (((TblCONTACT.CompanyID)=" & cmbString & "))"
myRecordSet.Open mySQL
txtTitle = myRecordSet("Title")
txtForename2 = myRecordSet("forename")
txtSurname2 = myRecordSet("surname")
txtPosition = myRecordSet("position")
txtDept = myRecordSet("Dept")
txtTelNo = myRecordSet("TelephoneNo")
txtMobNo = myRecordSet("MobilePhone")
txtHomeNo = myRecordSet("HomeTelNo")
txtFaxNo = myRecordSet("faxnumber")
'txtURL = myRecordSet("URL")
txtemail1 = myRecordSet("email1")
txtemail2 = myRecordSet("email2")
'txtsource = myRecordSet("source")
txtsms = myRecordSet("sms")
txtBusName = myRecordSet("BusinessName")
txtBusType = myRecordSet("BusinessType")
txtAdd1 = myRecordSet("address1")
txtAdd2 = myRecordSet("address2")
txtadd3 = myRecordSet("address3")
txtAdd4 = myRecordSet("address4")
txtTownCity = myRecordSet("TownCity")
txtRegion = myRecordSet("Region")
txtPostcode2 = myRecordSet("Postcode")
txtEmployeeNo = myRecordSet("EmployeeNo")
txtSIC = myRecordSet("SIC")
txtSICDescription = myRecordSet("SICCategory")
txtTurnover = myRecordSet("Turnover")
Set myRecordSet = Nothing
Set cnn1 = Nothing
End Sub