|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
addnew help
I am trying to develp a small program that has access db in the background.
I type items in my form, hit "Save" and I get an error msg. I then hit the debug button, it takes me to rs.update here is my code Option Explicit Dim db As Database Dim rs As Recordset Private Sub Form_Load() Dim x Set db = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\homefirst.mdb") Set rs = db.OpenRecordset("companyinfo") End Sub Private Sub cmdClear_Click() 'Clears the text in all the fields. txtSalesTaxRate.Text = "" cboSalesTaxState.Text = "" cboPaymentTerms.Text = "" txtInvoiceDes.Text = "" txtPhone.Text = "" textFAX.Text = "" txtCompanyName.Text = "" txtStreetZip.Text = "" cboStreetState.Text = "" txtStreetCity.Text = "" txtZip.Text = "" cboMailingState.Text = "" txtMailingCity.Text = "" txtMailingAddress.Text = "" txtstreetAddress.Text = "" txtEstimateDes.Text = "" 'Moves curser to top of form. txtCompanyName.SetFocus End Sub Private Sub cmdExit_Click() 'Ends the program without saving. End End Sub Private Sub cmdSave_Click() 'Set database Set rs = db.OpenRecordset("companyinfo") If txtSalesTaxRate.Text = "" Or _ cboSalesTaxState.Text = "" Or _ cboPaymentTerms.Text = "" Or _ txtInvoiceDes.Text = "" Or _ txtPhone.Text = "" Or _ txtFax.Text = "" Or _ txtCompanyName.Text = "" Or _ txtStreetZip.Text = "" Or _ cboStreetState.Text = "" Or _ txtStreetCity.Text = "" Or _ txtZip.Text = "" Or _ cboMailingState.Text = "" Or _ txtMailingCity.Text = "" Or _ txtMailingAddress.Text = "" Or _ txtstreetAddress.Text = "" Or _ txtEstimateDes.Text = "" Then MsgBox "Please fill all the boxes." Else rs.AddNew rs!SalesTaxRate = txtSalesTaxRate.Text rs!SalesTaxState = cboSalesTaxState.Text rs!DefaultPaymentTerms = cboPaymentTerms.Text rs!DefaultInvoiceDescription = txtInvoiceDes.Text rs!PhoneNumber = txtPhone.Text rs!FaxNumber = txtFax.Text rs!CompanyName = txtCompanyName.Text rs!StreetZip = txtStreetZip.Text rs!StreetState = cboStreetState.Text rs!StreetCity = txtStreetCity.Text rs!MailingZip = txtZip.Text rs!MailingState = cboMailingState.Text rs!MailingCity = txtMailingCity.Text rs!MailingAddress = txtMailingAddress.Text rs!StreetAddress = txtstreetAddress.Text rs!DefaultEstimateDescription = txtEstimateDes.Text rs.Update End If Unload Me rs.Close End Sub I can be reached by AIM - nustartec msn - URL Y! - jmyers_nc please help jeff |
|
#2
|
||||
|
||||
|
ok - I have a few problems here - 1. Are you doing this in VB6, or VBA? I've seen several people using the "Dim db as Database" syntax lately, and I would strongly suggest that you use traditional ADO if possible. 2. You have declared a module level recordset, and in form_load, you are opening that recordset. Then in your click event, you're opening it again. Is there a reason for this? I don't think that this is your problem, but I'm curious.
I would strongly suggest the former, however. ADO has methods of checking for errors and more detailed error messages. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > addnew help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|