Solved

automation error in exe files

Posted on 2002-05-10
2
129 Views
Last Modified: 2010-05-02
I use the following code to generate automatic numbers in my form. The code works well within VB. When the project is made as exe file, it shows "Automation Error" when there is no records in the database. It makes no problems when there are some records already existing in the concerned table. I am using MS Access as the back end.

Public Sub proNewNumberGeneration()
Dim rs2 As ADODB.Recordset
Set rs2 = New ADODB.Recordset
Dim strnnsql As String
strnnsql = "select max(ReciptNo) from CashRecipts"
rs2.Open strnnsql, adocn
adocn.Execute strnnsql
If rs2(0) > 0 Then
                q = "CR"
                c = Mid(rs2(0), 3, 6)
                d = Format(Val(c) + 1, "0000")
                cboReceiptno.Text = q & d
Else
              cboReceiptno.Text = "CR0001"

End If
End Sub

0
Comment
Question by:r_venkatadhri
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
Comment Utility
Add a test for .eof

If rs2.Eof Then
  cboReceiptNo.Text = "CR0001"
Else
  If rs2(0) > 0 Then
    'continue with the rest of your code
End If

This will ensure that if there are no records you get the default.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
good!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now