Solved

automation error in exe files

Posted on 2002-05-10
2
130 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

911 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

20 Experts available now in Live!

Get 1:1 Help Now