Solved

Merge

Posted on 2009-06-30
2
300 Views
Last Modified: 2013-11-25
How to correct the code below wherein I want to merge  the two field in one table?
'Class mudule

Public Function Merged(ProCode As String) As String

Dim Merge(1 To 2) As String

Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset

Dim sql As String

Set rs = New ADODB.Recordset

    sql = "select Top 1 Tag_Name,  Quantity from STOCK where PROCODE='" & ProCode & "'"

    rs.LockType = adLockOptimistic

    rs.CursorType = adOpenKeyset

    rs.Open sql, cn

    With rs

        If .BOF = True And _

            .EOF = True Then

            Merge(1) = ""

            Merge(2) = (0)

        Else

            Merge(1) = !Tag_Name & ""

            Merge(2) = !Quantity

        End If

        .Close

    End With

    Set rs = Nothing

End Function
 

'Form

Public Sub Tag1()

Dim s As Labeler

Set s = New Labeler

s.OPEN_CON "mydb", ""

Dim j As SSCommand

For Each j In cmd1

    j.Caption = s.Merge(1)(j.Index) & vbNewLine & s.Merge(2)(j.Index)

Next

s.CLOSE_CON

Set s = Nothing

End Sub

Open in new window

0
Comment
Question by:Whing Dela Cruz
2 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 24750654
I really don't know what you are asking for. It is not really clear again!

One thing for sure is that Merge is a variable local to the Merged Function so it cannot be accessed outside it (and you try to do just that.

could you try this:

'Class mudule

PUBLIC Merge(1 To 2) As String
 

Public sub Merged(ProCode As String) 

Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset

Dim sql As String

Set rs = New ADODB.Recordset

    sql = "select Top 1 Tag_Name,  Quantity from STOCK where PROCODE='" & ProCode & "'"

    rs.LockType = adLockOptimistic

    rs.CursorType = adOpenKeyset

    rs.Open sql, cn

    With rs

        If .BOF = True And _

            .EOF = True Then

            Merge(1) = ""

            Merge(2) = (0)

        Else

            Merge(1) = !Tag_Name & ""

            Merge(2) = !Quantity

        End If

        .Close

    End With

    Set rs = Nothing

End sub

 

'Form

Public Sub Tag1()

Dim s As Labeler

Set s = New Labeler

s.OPEN_CON "mydb", ""

Dim j As SSCommand

For Each j In cmd1

    call s.Merged(j.Index)

    j.Caption = s.Merge(1) & vbNewLine & s.Merge(2)

Next

s.CLOSE_CON

Set s = Nothing

End Sub

Open in new window

0
 

Author Closing Comment

by:Whing Dela Cruz
ID: 31598483
Thank you sir, Through this idea i was able to solve the problem..
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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

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

23 Experts available now in Live!

Get 1:1 Help Now