I have written an excel application that loops through an access 2003 database of contacts.
Code:
DoEvents
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
'Open the ADO Connection
Set conn = New ADODB.Connection
strDatabase = wsSetup.Cells(1, 2)
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= '" & strDatabase & "'"
conn.Open
' Select the data.
Set rs = conn.Execute( _
"SELECT * FROM tblCustomer", , _
adCmdText)
Row = 1
Do While Not rs.EOF
For col = 0 To rs.Fields.Count - 1
wsData.Cells(Row, col + 1) = _
rs.Fields(col).Value
Next col
Row = Row + 1
rs.MoveNext
Loop
' Close the database.
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
This brings in all the contacts into a hidden temporary sheet. Then Vba code selects distinct companies and displays a list of contacts for each company. If the contact isn't in the list a button can be pressed to allow the addition of a new contact. Using this code:
Code:
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
strDatabase = wsSetup.Cells(1, 2)
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & strDatabase & "'"
conn.Open
Dim strContactName, strCompany, strPhone, strFax, strEmail, strAddress1, _
strCity, strState, strZIP As String
strContactName = frmNewContact.txtContactName
strCompany = frmNewContact.txtCompany
strPhone = frmNewContact.txtPhone
strFax = frmNewContact.txtFax
strEmail = frmNewContact.txtEmail
strAddress1 = frmNewContact.txtAddress1
strCity = frmNewContact.txtCity
strState = UCase(frmNewContact.txtState)
strZIP = frmNewContact.txtZIP
Dim strSQL As String
strSQL = "INSERT INTO tblCustomer(ContactName, Company, WorkNO, FaxNO, Email, Address, City, State, Zip)VALUES('" & strContactName & "', '" & strCompany & "', '" & strPhone & "', '" & strFax & "', '" & strEmail & "', '" & strAddress1 & "', '" & strCity & "', '" & strState & "', '" & strZIP & "')"
conn.Execute strSQL
conn.Close
Set conn = Nothing
Randomly the database will stop selecting all records from the database. Even though the records do exist and can be updated via Access. I have tried repairing the database with Access with no luck. I have also tried selecting the data with a another stripped down version of my application from the same database and that works as far as I can see. So, is there something that is not clearing or.....
Any ideas?