VB6 DATAGRID , LIVEDATA , UPDATE

VB6 DataGrid , Update and new

Page 1 of 1

7 Replies - 28259 Views - Last Post: 03 June 2008 - 08:28 AM Rate Topic: -----

#1 blee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 01-June 08

VB6 DATAGRID , LIVEDATA , UPDATE

Posted 01 June 2008 - 09:58 AM

HI

I am working on small project with VB6.

Phases of Project[u]

a) Creating an Ordering Sytem to place Order.
B) Checking in Items as they are Received.
c) Generating a Report on wich Items will be display that has not been received.

I am using DataGrid. and I am but Rusty with VB6.

I have Two Tables
a) Order
Supplier , date , Delivery , Contact Person ,Order Total , VAT ex.
B) Order Details
Qty , Description , Unit Price , Total

They are link by Order Number.



I want to create new Order.
1) Fill in the TextBoxes for Order Table
2) Use DataGrid for OrderDetails.

What is the Best way of Doing This ??

I have create the Interface and the Code , but is not working !!
Anyone who are will to help me .

Thanks
Peter

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: VB6 DATAGRID , LIVEDATA , UPDATE

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: VB6 DATAGRID , LIVEDATA , UPDATE

Posted 01 June 2008 - 10:01 AM

[rules][/rules]


Post what you've worked on and we will be more than happy to help you through your project
Was This Post Helpful? 0
  • +
  • -

#3 blee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 01-June 08

Re: VB6 DATAGRID , LIVEDATA , UPDATE

Posted 01 June 2008 - 10:39 AM

Please find my attached File for CODE to must to Copy and Past

 
Dim NewOrderNumber As Integer
Dim OrderTotalPrice As Double

Private Sub cmdAddItem_Click()

Dim UnitPrice As Double
Dim UnitQty As Double
Dim UnitTotal As Double



' Check Users Input


If txtOrderQty.Text = "" Then
    MsgBox ("Please Enter Valid Qty ! ")
    Exit Sub
End If
    
If txtOrderUnits.Text = "" Then
    MsgBox ("Please enter Valid Units")
    Exit Sub
End If

If txtOrderDescription.Text = "" Then
    MsgBox ("Please Enter Valid Description")
    Exit Sub
End If

If txtUnitPrice.Text = "" Then
    MsgBox ("Please Enter Valid Unit Price")
    Exit Sub
End If

' Add new Item to Order

DeData.rsComOrderDetailsPlace.AddNew
DeData.rsComOrderDetailsPlace!OrderNumber = txtOrderNumber.Text
DeData.rsComOrderDetailsPlace!OrderQty = txtOrderQty.Text
DeData.rsComOrderDetailsPlace!OrderUnits = txtOrderUnits.Text
DeData.rsComOrderDetailsPlace!OrderDescription = txtOrderDescription.Text
DeData.rsComOrderDetailsPlace!OrderUnitPrice = txtUnitPrice.Text

' Calculates Unit Total
UnitPrice = Val(txtUnitPrice.Text)
UnitQty = Val(txtOrderQty.Text)

UnitTotal = UnitPrice * UnitQty

txtOrderTotalUnitPrice.Text = CCur(UnitTotal)

' Calculates  OrderTotal for Global Value
    OrderTotalPrice = OrderTotalPrice + UnitTotal

' Add unitTotal to Database
DeData.rsComOrderDetailsPlace!OrderUnitTotal = UnitTotal

txtOrderNetInvoice.Text = OrderTotalPrice


DeData.rsComOrderDetailsPlace.Update

DeData.rsComOrders.UpdateBatch



MsgBox (OrderTotalPrice)
End Sub



Private Sub cmdMoveFirst_Click()
DeData.rsComOrders.MoveFirst
End Sub

Private Sub cmdMoveLast_Click()
 
  DeData.rsComOrders.MoveLast
 
End Sub

Private Sub cmdMoveNext_Click()

    DeData.rsComOrders.MoveNext

If DeData.rsComOrders.EOF = True Then
 DeData.rsComOrders.MoveLast
 
End If

End Sub

Private Sub Command2_Click()
rsOrder.MoveNext
End Sub

Private Sub cmdPlaceOrder_Click()

DeData.Commands.rsComOrders.MoveLast

'If DeData.rsComOrders!OrderNumber = NewOrderNumber Then


txtOrderNetInvoice.Text = OrderTotalPrice


'   End If
End Sub

Private Sub dgOrder_AfterColEdit(ByVal ColIndex As Integer)
Dim NetTotal As Double

Qty = Val(dgOrder.Columns(1).CellText(dgOrder.Bookmark))
UnitPrice = Val(dgOrder.Columns(5).CellText(dgOrder.Bookmark))

Mark = dgOrder.Bookmark

TotalPrice = Qty * UnitPrice

dgOrder.Columns(6).Value = TotalPrice

' Calculate Net Invoice Value
    
test = dgOrder.ApproxCount

Startno = 1
Stopno = DeData.rsComOrderDetailsPlace.RecordCount
NetTotal = 0

DeData.rsComOrderDetailsPlace.MoveFirst

For i = 1 To Stopno

If DeData.rsComOrderDetailsPlace!OrderNumber = dgOrder.Columns(OrderNumber) Then

NetTotal = NetTotal + Val(DeData.rsComOrderDetailsPlace!OrderUnitTotal)
'MsgBox (DeData.rsComOrderDetailsPlace!OrderUnitPrice)

Else
    
End If
DeData.rsComOrderDetailsPlace.MoveNext
Next

txtOrderNetInvoice.Text = NetTotal

End Sub

Private Sub Form_Load()
Call GenOrderNumber

DeData.rsComOrderDetailsPlace.Open
dgOrder.Columns(OrderNumber).Visible = False
dgOrder.Columns(7).Visible = False
dgOrder.Columns(8).Visible = False

dgOrder.Columns(1).Width = 500
dgOrder.Columns(2).Width = 600
dgOrder.Columns(3).Width = 5500
dgOrder.Columns(4).Width = 800
dgOrder.Columns(4).Alignment = dbgCenter
dgOrder.Columns(5).Alignment = dbgRight
dgOrder.Columns(6).Alignment = dbgRight
dgOrder.Columns(5).Width = 1300
dgOrder.Columns(6).Width = 1300

radInclusive.Value = True
End Sub

Private Sub MovePrev_Click()


    DeData.rsComOrders.MoveFirst

If DeData.rsComOrders.BOF = True Then
    DeData.rsComOrders.MovePrevious
    End If

End Sub

Public Sub UserInput()

'Check for User Input
    If txtOrderSupplier.Text = "" Then
        MsgBox ("Please Enter Valid Supplier Name ")
        Exit Sub
     End If
    If txtOrderContact.Text = "" Then
        MsgBox ("Please Enter Valid Contact Person ")
        Exit Sub
    End If
    If txtOrderDate.Text = "" Then
        MsgBox ("Please Enter Valid Date ")
        Exit Sub
    End If
    If txtOrderReference.Text = "" Then
        MsgBox ("Please Enter Valid MET Number")
        Exit Sub
    End If
End Sub


End If

End Sub

Private Sub radExclusive_Click()

Dim TaxAmount As Double

If radExclusive.Value = True Then

    txtOrderTaxAmount.Text = 0
Else
    TaxAmount = Val(txtOrderNetInvoice.Text) * 0.14
    txtOrderTaxAmount.Text = TaxAmount
End If
End Sub

Private Sub radInclusive_Click()

Dim TaxAmount As Double

If radExclusive.Value = True Then

    txtOrderTaxAmount.Text = 0
Else
    TaxAmount = Val(txtOrderNetInvoice.Text) * 0.14
    txtOrderTaxAmount.Text = TaxAmount
End If
End Sub

Private Sub txtOrderNetInvoice_Change()

Dim TaxAmount As Double

If radExclusive.Value = True Then

    txtOrderTaxAmount.Text = 0
Else
    TaxAmount = Val(txtOrderNetInvoice.Text) * 0.14
    txtOrderTaxAmount.Text = TaxAmount
End If

End Sub

Private Sub txtOrderTotalUnitPrice_GotFocus()
Dim UnitPrice As Double
Dim UnitQty As Double
Dim UnitTotal As Double

UnitPrice = Val(txtUnitPrice.Text)
UnitQty = Val(txtOrderQty.Text)

UnitTotal = UnitPrice * UnitQty

txtOrderTotalUnitPrice.Text = CDec(UnitTotal)
End Sub



Public Sub GenOrderNumber()
   
DeData.rsComOrders.MoveLast

NewOrderNumber = DeData.rsComOrders!OrderNumber
NewOrderNumber = NewOrderNumber + 1

End Sub


This post has been edited by PsychoCoder: 02 June 2008 - 12:30 PM

Was This Post Helpful? 0
  • +
  • -

#4 mensahero  Icon User is offline

  • I Desire...
  • member icon

Reputation: 17
  • View blog
  • Posts: 678
  • Joined: 26-May 08

Re: VB6 DATAGRID , LIVEDATA , UPDATE

Posted 02 June 2008 - 11:13 AM

please use the code bracket as indicated by PsychoCoder..

what part exactly of the code that does not work...? you forgot to include the database you are actually working on...

please be specific and define the error or part of your program that is not working.. simply saying "help its not working" is not really informative..

Some tip:

1. Attach the database in the same folder as your application resides..
refer to it as ( ie: app.path + "\myDb.mdb" )

2. To create a datagrid that display orders that has not been recieved by the customer.. this structure should work..

a. in the order table add a boolean field ( field that contains yes/no, true/false )
b. add a adodc object in your form and connect it to the database file.
c. add a method that will filter the adodc to display orders that contain a false record in the recieved field using SQL SELECT..
d. set the datagrid datasource to use the adodc object

This post has been edited by mensahero: 02 June 2008 - 11:25 AM

Was This Post Helpful? 0
  • +
  • -

#5 blee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 01-June 08

Re: VB6 DATAGRID , LIVEDATA , UPDATE

Posted 02 June 2008 - 11:40 AM

View Postmensahero, on 2 Jun, 2008 - 11:13 AM, said:

please use the code bracket as indicated by PsychoCoder..

what part exactly of the code that does not work...? you forgot to include the database you are actually working on...

please be specific and define the error or part of your program that is not working.. simply saying "help its not working" is not really informative..

Some tip:

1. Attach the database in the same folder as your application resides..
refer to it as ( ie: app.path + "\myDb.mdb" )

2. To create a datagrid that display orders that has not been recieved by the customer.. this structure should work..

a. in the order table add a boolean field ( field that contains yes/no, true/false )
b. add a adodc object in your form and connect it to the database file.
c. add a method that will filter the adodc to display orders that contain a false record in the recieved field using SQL SELECT..
d. set the datagrid datasource to use the adodc object



HI

Thanks for Your Reply.

Should I used the textboxes to add the Items one by one with code to the Order Details Table.
eg 2 Items under Order 606.

6 Bolts 6543 $50.00 $300.00
6 Nuts 7363 $2.00 $12.00

That I Understand , I have link my data Grid to that Table , But If I update the new entry's my Table stay clean.
What should I do the to get the Datagrid to show new Entry . with out closing my App and reopening it.

Here is my database File place in root :c:\

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#6 mensahero  Icon User is offline

  • I Desire...
  • member icon

Reputation: 17
  • View blog
  • Posts: 678
  • Joined: 26-May 08

Re: VB6 DATAGRID , LIVEDATA , UPDATE

Posted 03 June 2008 - 01:36 AM

by trying your project I've notice somethings that is causing the datagrid not to show newly added records..


first problem:

1. your datagrid only display records with an orderNumber "300" .. why?

2. your newly added items doesn't contain an autoGenerated orderNumber or something that will set its orderNumber to a value...

3. if you accomplish both 1 and 2.. the only problem left is that your add item doesn't have a code that refreshes the datagrid..

example: when the newly item is added..
set datagrid.datasource = nothing
datagrid.refresh
set datagrid.datasource = dedata
frmOrder.refresh

well thats a pseudo code.. but something like that should work in refreshing the datagrid..

* You must first solve problem number 1 and 2.. before you can apply number 3..
Was This Post Helpful? 0
  • +
  • -

#7 blee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 01-June 08

Re: VB6 DATAGRID , LIVEDATA , UPDATE

Posted 03 June 2008 - 07:47 AM

View Postmensahero, on 3 Jun, 2008 - 01:36 AM, said:

by trying your project I've notice somethings that is causing the datagrid not to show newly added records..


first problem:

1. your datagrid only display records with an orderNumber "300" .. why?

2. your newly added items doesn't contain an autoGenerated orderNumber or something that will set its orderNumber to a value...

3. if you accomplish both 1 and 2.. the only problem left is that your add item doesn't have a code that refreshes the datagrid..

example: when the newly item is added..
set datagrid.datasource = nothing
datagrid.refresh
set datagrid.datasource = dedata
frmOrder.refresh

well thats a pseudo code.. but something like that should work in refreshing the datagrid..

* You must first solve problem number 1 and 2.. before you can apply number 3..



thanks for your replay

I got the Order number sorted.

Still having same problem with datagrid only showing last Data add to OrderReference Table before Closing and reoping Project . Not the new Record I have just create with Add Item Button

I have Update the Database and Program.
Will you Please Have look and Advice me


Please find Attachment .

Thanks for Helping me

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#8 mensahero  Icon User is offline

  • I Desire...
  • member icon

Reputation: 17
  • View blog
  • Posts: 678
  • Joined: 26-May 08

Re: VB6 DATAGRID , LIVEDATA , UPDATE

Posted 03 June 2008 - 08:28 AM

hello.. well again by testing your program and I think I have a slight IDEA of what you want to do..

your task:

You create a form that will provide complete information about an order.
.. this is what our orderReference table for..

a single record order(order table) could contain many orderReference..


well to that part I understand what your doing but your program is badly structured and designed to achieved this..

based from my understanding of your program flow here is your problem..

1. users must input manually a STATIC UNIQUE orderNumber in the HDM labeled textbox. (bad design)

2. the datagrid will only diplay newly added recordReference order with an orderNumber equal to the first orderNumber provided by the user.

3. After the user finished ADDING ITEMS.. he will place the order and the newly added record on the record table would contain an order number equal to the first orderNumber provided by the user.


you should think deep about those 3 because they are the main processes of your program...

lastly.. your current program is badly designed to handle those 3.. try reading your code line by line and understand better your program flow..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1