[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Code Lacking

Posted on 2009-04-03
9
Medium Priority
?
268 Views
Last Modified: 2012-05-06
What's wrong in my code below? I'm using msflexgrid. It doesn't save correctly
Public Sub OPEN_CON1(cn As ADODB.Connection, db As String, ServerName As String)
Set cn = New ADODB.Connection
cn.Provider = "sqloledb"
cn.ConnectionTimeout = 25
cn.Properties("Data source").Value = Trim(ServerName)
cn.Properties("Initial Catalog").Value = Trim(db)
cn.Properties("User ID").Value = "sa"
cn.Properties("Password").Value = ""
cn.CursorLocation = adUseClient
cn.Open , "sa", ""
End Sub
Public Sub save_Table(cn As ADODB.Connection, lpTable_No As String, Customer_name As String, Time_in As String, Time_Out As String)
Dim rs As ADODB.Recordset
Dim sql As String
Set rs = New ADODB.Recordset
    sql = "select * from The_Table where Table_No='" & lpTable_No & "'"
    rs.LockType = adLockOptimistic
    rs.CursorType = adOpenKeyset
    rs.Open sql, cn
    With rs
        If .BOF = True And _
            .EOF = True Then
            .AddNew
            !Table_No = lpTable_No
        End If
        !Customer_name = grid.TextMatrix(grid.Row, 1)
        !Time_in = Trim(grid.TextMatrix(grid.Row, 2))
        !Time_Out = grid.TextMatrix(grid.Row, 3)
        .Update
        .Close
    End With
    Set rs = Nothing
End Sub
Private Sub CmdSave()
Dim cn As ADODB.Connection
Call OPEN_CON1(cn, "MyTable", "Winpos")
Call save_Table(cn, grid.TextMatrix(grid.Row, 0), grid.TextMatrix(grid.Row, 1), grid.TextMatrix(grid.Row, 2), grid.TextMatrix(grid.Row, 3))
Set cn = Nothing
End Sub

Open in new window

grid.bmp
0
Comment
Question by:Whing Dela Cruz
[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
  • 5
  • 2
  • 2
9 Comments
 

Author Comment

by:Whing Dela Cruz
ID: 24065693
It saved only the last data of the table. example above " 1 Humbang Baboy " the rest did not saved.
0
 
LVL 5

Expert Comment

by:mrcoolcoder
ID: 24066019
You do not have a loop and you are passing in the values to your sub but not using them.  You need to set the current row as the grid will not loop within itself.

There are many ways to do this, but try this.
Private Sub CmdSave()
Dim cn As ADODB.Connection
Call OPEN_CON1(cn, "MyTable", "Winpos")
dim iRow as Integer
For iRow = 0 to 3
grid.row = iRow
Call save_Table(cn, grid.TextMatrix(grid.Row, 0), grid.TextMatrix(grid.Row, 1), grid.TextMatrix(grid.Row, 2), grid.TextMatrix(grid.Row, 3))
Set cn = Nothing
End Sub

Open in new window

0
 
LVL 5

Expert Comment

by:mrcoolcoder
ID: 24066025
sorry forgot the "next"
Private Sub CmdSave()
Dim cn As ADODB.Connection
Call OPEN_CON1(cn, "MyTable", "Winpos")
dim iRow as Integer
For iRow = 0 to 3
    grid.row = iRow
    Call save_Table(cn, grid.TextMatrix(grid.Row, 0), grid.TextMatrix(grid.Row, 1), grid.TextMatrix(grid.Row, 2),    grid.TextMatrix(grid.Row, 3))
Next
Set cn = Nothing
End Sub

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Whing Dela Cruz
ID: 24066197
Hi!
i tried the given code and  it was able to saved the entire row but the problem is only the last row was saved. the first and the second to the last row was not.
What else should i do?
thanks!
0
 
LVL 11

Accepted Solution

by:
Antagony1960 earned 1500 total points
ID: 24066472
You also need to change lines 26 to 28 of your original code, so that the save_Table procedure uses the values passed as arguments rather than direct grid references:
        !Customer_name = Customer_name
        !Time_in = Time_in
        !Time_Out = Time_Out

Open in new window

0
 

Author Comment

by:Whing Dela Cruz
ID: 24066685
Hi!
you mean like this;

        !Customer_name = Customer_name = grid.TextMatrix(grid.Row, 1)
        !Time_in = Time_in = Trim(grid.TextMatrix(grid.Row, 3))
        !Time_Out = Time_Out = grid.TextMatrix(grid.Row, 5)
       
0
 

Author Comment

by:Whing Dela Cruz
ID: 24066771
Hi!
I need to move same set of question because i had changed some part of my table.
I hope you will monitor on it..
Thanks!
0
 
LVL 11

Expert Comment

by:Antagony1960
ID: 24067295
Sorry for not replying sooner, unbeknownst to me my POP email server has been down so I wasn't getting alerts.

<<you mean like this;>>

Erm... no, I meant it just like I posted it. What you have done there will try and set each field to either True or False (-1 or 0) depending on whether the passed argument values match the columns you're specifying explicitly there. You're already specifying which columns of the grid to use when you call the save_Table procedure from CmdSave, so there shouldn't be any need for you to reference the grid from within the procedure itself.
0
 

Author Comment

by:Whing Dela Cruz
ID: 24067330
I'm very sorry but i could not exactly understand what you meant for...
Can you move to my other set of question because i transfered it for more details in my problem.
Thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Suggested Courses

650 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