Welcome to Dream.In.Code
Become a VB Expert!

Join 149,916 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,110 people online right now. Registration is fast and FREE... Join Now!




Code Gen problem

 
Reply to this topicStart new topic

Code Gen problem, Code Gen by name

rookieLP
18 Dec, 2007 - 02:48 AM
Post #1

New D.I.C Head
*

Joined: 1 Sep, 2007
Posts: 26


My Contributions
i'm tryin to generate code by usin the 1st character 4m Cmbptype,i have different existin code H00001,M00004,R00003.....
since i use
CODE
val(rec(0))
dependin on type i tryin 2 increment the code.........
CODE

if rec.state>0 then rec.close
rec.open "select max(mid(Prod_code,2)) from product",conn,adopendynamic,adlockoptimistic

if isnull(rec(0)) then
txtcode=ucase(left(cmbptype,1)) & "00001"
else
txtcode=ucase(left(cmbptype,1)) &format(val(rec(0)) +1,"00000")

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Code Gen Problem
18 Dec, 2007 - 11:53 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
And what kind of problem are you having? Any error messages? I would take a look at your format() function and see if the problem is there. My guess is that it is not giving you the value you expect. Is rec(0) defined as a string in the database? If so you may need to convert it to something like an integer using CInt and then add the one to it.

Let us know what is actually going wrong with this code. Thanks! smile.gif
User is offlineProfile CardPM
+Quote Post

rookieLP
RE: Code Gen Problem
21 Dec, 2007 - 06:06 AM
Post #3

New D.I.C Head
*

Joined: 1 Sep, 2007
Posts: 26


My Contributions
weneva i select add new & select the comboBox it gives me
(the comboBox )00004 value for all records.........
the code above is stuff i was tryin so no duplicate entries are created....din know how exactly to do it,
this is the original function i used:
CODE
Private Function codgen() As String
Dim rec
Dim conn
Dim cmd
    On Error Resume Next
    cmd = New ADODB.Command
    Set rec = New ADODB.Recordset
    Set conn = New ADODB.Connection
     conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & App.Path & "\Db3.mdb"
    conn.Open
    cmd.ActiveConnection = conn
    If rec.State > 0 Then rec.Close
    rec.Open "select max(mid(Sup_id,2)) from supplier", conn, adOpenDynamic, adLockOptimistic
    If IsNull(rec(0)) Then
        codgen = "S00001"
    Else
        codgen = "S" & Format(Val(rec(0)) + 1, "00000")
    End If
    txtcode = codgen
End Function


i posted 2 forms wit Db
thanxAttached File  code.zip ( 15.52k ) Number of downloads: 28

User is offlineProfile CardPM
+Quote Post

rookieLP
RE: Code Gen Problem
22 Dec, 2007 - 09:40 AM
Post #4

New D.I.C Head
*

Joined: 1 Sep, 2007
Posts: 26


My Contributions
is der a way 2do dat??????
sumtin like searchin 4d code letter&& selectin d largest no+1.......
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 02:27PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month