Solved

automation error in exe files

Posted on 2002-05-10
2
133 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
ID: 7001633
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
ID: 7001931
good!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

751 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