Refreash a MS DataGrid

Refreash a MS DataGrid

Anonymous
Not applicable
415 Views
3 Replies
Message 1 of 4

Refreash a MS DataGrid

Anonymous
Not applicable
Does anyone know how to get a datagrid to refresh
after adding a record?  I'm using text boxes as fields then clicking a
command button to add the record.  Then I need the datagrid to update also
to show the new record.


--

Dave
Gardner
0 Likes
416 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Try myDataGrid.refresh or recordset.requery if you have a recordset bind to your datagrid.
0 Likes
Message 3 of 4

Anonymous
Not applicable
Those don't seem to work.  Here is my
code.  It is stand alone vb6.

 

Option Explicit
Option Compare
Text
'**********************************************************************************************************
'What
Database  BOM and
Records.mdb
'-------------------------------------Revision
Section-----------------------------------------------------
'1.0.0 Take out
drawing numbers only  ?/?/??
DMG
'**********************************************************************************************************
Dim
BOMDB As New ADODB.Connection
Dim BOMRS As New ADODB.Recordset
Dim
strSelect As String
Dim intDrawingID As Integer

 

Private Sub cmdClose_Click()
   
Unload Me
    Set frmBOM = Nothing
End Sub

 

Private Sub cmdAdd_Click()

 

    BOMDB.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\bhmm\Ward Common\Databases\BOM
and Records.mdb;Persist Security Info=False"
   
BOMDB.Open
    strSelect = "SELECT * FROM
BOMTable"
    BOMRS.Open strSelect, BOMDB, ,
adLockOptimistic
    Set dgrBOM.DataSource =
BOMRS
    With
BOMRS
       
.AddNew
        !DrawingNumberID =
intDrawingID
        !BOMItem =
txtItem
        !ItemQuantityPerAssy =
txtQtyPerAssy
        !NumberOfAssy =
txtNumOfAssy
        !TotalQuantity =
lblTotalQuantity
        !Description =
txtSizePattDraw
        !Material =
cboMaterial
       
.Update
       
.Close
    End With
    BOMDB.Close
'This
is where I need the datagrid to refresh.
    txtItem =
Val(txtItem) + 1
   
txtQtyPerAssy.SetFocus
    txtQtyPerAssy.SelStart =
0
    txtQtyPerAssy.SelLength =
Len(txtQtyPerAssy)
   
End Sub

 

Private Sub Form_Load()

 

    intDrawingID =
8
    strSelect = "select BOMItem, ItemQuantityPerAssy,
NumberOfAssy, TotalQuantity, Description, Material from bomtable where
bomtable.DrawingNumberID=" + CStr(intDrawingID) + " Order By
BOMItem"
    adoBOM.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\bhmm\Ward Common\Databases\BOM
and Records.mdb;Persist Security Info=False"
   
adoBOM.RecordSource = strSelect
    Set dgrBOM.DataSource =
adoBOM
    dgrBOM.Caption = "Bill Of Marterial for
501-07-DCFP-L3-00"

 

Dim strMatText As String
Dim strFileName As
String
Dim Filehandle%

 

    strFileName =
"I:\Borders\BuffInd Menu\BOM Material.txt"

 

    Filehandle% =
FreeFile
    Open strFileName For Input As
#Filehandle%

 

    Do While Not
EOF(Filehandle%)
        Line Input
#Filehandle%, strMatText
       
cboMaterial.AddItem strMatText
    Loop

 

    Close
#Filehandle%
'    dgrbom.Columns.Item(0) =
"Item"
'    dgrbom.Columns.Item(1) =
"QuantityPerAssy"
'    dgrbom.Columns.Item(2) =
"NumberOfAssy's"
'    dgrbom.Columns.Item(3) =
"TotalQuantity"
'    dgrbom.Columns.Item(4) = "SIZE, PATTERN,
DRAWING NUMBER"
'    dgrbom.Columns.Item(5) =
"Material"
End Sub

 

Private Sub
txtNumOfAssy_Change()
    If IsNumeric(txtNumOfAssy.Text) =
True Or (txtNumOfAssy.Text = "" Or txtNumOfAssy.Text = " " Or txtNumOfAssy.Text
= "  " Or txtNumOfAssy.Text = "   ")
_
        Then cmdAdd.Enabled = True Else
cmdAdd.Enabled = False
    lblTotalQuantity.Caption =
IIf((Val(txtQtyPerAssy.Text) * Val(txtNumOfAssy.Text)) = 0, "",
Val(txtQtyPerAssy.Text) * Val(txtNumOfAssy.Text))
End Sub

 

Private Sub
txtQtyPerAssy_Change()
    If IsNumeric(txtQtyPerAssy.Text) =
True Or (txtQtyPerAssy.Text = "" Or txtQtyPerAssy.Text = " " Or
txtQtyPerAssy.Text = "  " Or txtQtyPerAssy.Text = "   ")
_
        Then cmdAdd.Enabled = True Else
cmdAdd.Enabled = False
    lblTotalQuantity.Caption =
IIf((Val(txtQtyPerAssy.Text) * Val(txtNumOfAssy.Text)) = 0, "",
Val(txtQtyPerAssy.Text) * Val(txtNumOfAssy.Text))
End Sub


--


Dave Gardner


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Try
myDataGrid.refresh or recordset.requery if you have a recordset bind to your
datagrid.
0 Likes
Message 4 of 4

Anonymous
Not applicable
You don't need to reconnect each time you trigger the add button.

Private Sub cmdAdd_Click()
With adoBOM.Recordset
.AddNew
' Modify fields here
.Update
End With
' the control is updated automatically

'This is where I need the datagrid to refresh.
End Sub
0 Likes