PackrBabe71
October 7th, 2001, 02:08 PM
OK...I'm using an ADO datacontrol and a datagrid to update Access database tables. My table is being updated, but the datagrid does not refresh the data until after the next action. I've tried everything I know...the procedure is below:
Private Sub cmdUpdate_Click()
Dim vntButton, vntButtonIndex As Variant
Dim sngPercent As Single
Dim rsInventory As Recordset
'On Error GoTo ErrorMsg
'Validate user input.
If Not IsNumeric(txtIncrease) Then
MsgBox ("Sorry, input must be numeric!")
With txtIncrease
.Text = " "
.SetFocus
End With
ElseIf (CInt(txtIncrease.Text)) < -100 Then
MsgBox ("Number cannot be less than -100." & vbCrLf & _
"Please try again.")
With txtIncrease
.Text = " "
.SetFocus
End With
End If
vntButton = Array(1, 2, 3) 'Array declaration
If optCategory(1).Value = True Then 'Uses the array to determine
vntButtonIndex = vntButton(0) 'which option button is chosen
ElseIf optCategory(2).Value = True Then 'and assigns the correct value
vntButtonIndex = vntButton(1) 'to the variable.
ElseIf optCategory(3).Value = True Then
vntButtonIndex = vntButton(2)
End If
'Converts the text input into a variable used as the percentage.
sngPercent = (1 + (CSng(txtIncrease.Text) / 100))
'Performs the update command and calculations on appropriate records.
mstrSQL = "UPDATE tblInventory " & _
"SET fldCost = fldCost * " & sngPercent & "" & _
" WHERE fldCategory = " & vntButtonIndex & ""
'Executes the command and refreshes the DB and grid.
mcmdCurrent.CommandText = mstrSQL
mcmdCurrent.Execute
adInventory.Recordset.Requery
adInventory.Recordset.Update
adInventory.Refresh
dgInventory.Refresh
Exit Sub
'Displays error description in message box.
ErrorMsg:
MsgBox (Err.Description & "--" & "Error Number " & Err.Number & _
vbCrLf & "Please try again.")
With txtIncrease
.Text = " "
.SetFocus
End With
End Sub
Private Sub cmdUpdate_Click()
Dim vntButton, vntButtonIndex As Variant
Dim sngPercent As Single
Dim rsInventory As Recordset
'On Error GoTo ErrorMsg
'Validate user input.
If Not IsNumeric(txtIncrease) Then
MsgBox ("Sorry, input must be numeric!")
With txtIncrease
.Text = " "
.SetFocus
End With
ElseIf (CInt(txtIncrease.Text)) < -100 Then
MsgBox ("Number cannot be less than -100." & vbCrLf & _
"Please try again.")
With txtIncrease
.Text = " "
.SetFocus
End With
End If
vntButton = Array(1, 2, 3) 'Array declaration
If optCategory(1).Value = True Then 'Uses the array to determine
vntButtonIndex = vntButton(0) 'which option button is chosen
ElseIf optCategory(2).Value = True Then 'and assigns the correct value
vntButtonIndex = vntButton(1) 'to the variable.
ElseIf optCategory(3).Value = True Then
vntButtonIndex = vntButton(2)
End If
'Converts the text input into a variable used as the percentage.
sngPercent = (1 + (CSng(txtIncrease.Text) / 100))
'Performs the update command and calculations on appropriate records.
mstrSQL = "UPDATE tblInventory " & _
"SET fldCost = fldCost * " & sngPercent & "" & _
" WHERE fldCategory = " & vntButtonIndex & ""
'Executes the command and refreshes the DB and grid.
mcmdCurrent.CommandText = mstrSQL
mcmdCurrent.Execute
adInventory.Recordset.Requery
adInventory.Recordset.Update
adInventory.Refresh
dgInventory.Refresh
Exit Sub
'Displays error description in message box.
ErrorMsg:
MsgBox (Err.Description & "--" & "Error Number " & Err.Number & _
vbCrLf & "Please try again.")
With txtIncrease
.Text = " "
.SetFocus
End With
End Sub