Option Explicit Private recCost As New ADODB.Recordset Private logCellRow As Long '记录HFGICost控件的行数 Private logCellCol As Long '记录HFGICost控件列数'将TxtCellEditor控件显示于正确位置 Private Sub ShowCellEditor() With HFGCost .RowSel = .Row .ColSel = .Col TxtCellEditor.Move .Left + .CellLeft, .Top + .CellTop, _ .CellWidth - ScaleX(1, vbPixels, vbTwips), .CellHeight _ - ScaleX(1, vbPixels, vbTwips) TxtCellEditor.Text = .Text TxtCellEditor.SelStart = 0 TxtCellEditor.SelLength = Len(TxtCellEditor.Text) TxtCellEditor.Visible = True TxtCellEditor.ZOrder TxtCellEditor.SetFocus logCellRow = .Row logCellCol = .Col End With End Sub'借助TxtCellEditor控件修改网格控件内的值(TxtCellEditor的编辑功能) Private Sub HideCellEditor(Optional Cancel As Boolean) Dim i As Integer If TxtCellEditor.Visible Then If Not Cancel Then HFGCost.TextMatrix(logCellRow, logCellCol) = TxtCellEditor.Text If recCost.State Then recCost.MoveFirst Dim intTemp As Integer intTemp = logCellRow - 1 Do While intTemp If recCost.State And Not (recCost.EOF) Then recCost.MoveNext intTemp = intTemp - 1 Loop If recCost.State Then recCost.Fields(logCellCol).Value = TxtCellEditor.Text End If TxtCellEditor.Visible = False End If End Sub'双击网格TxtCellEditor编辑功能被激活 Private Sub HFGCost_DblClick() ShowCellEditor End Sub '敲击键盘TxtCellEditor编辑功能被激活 Private Sub HFGCost_KeyPress(KeyAscii As Integer) ShowCellEditor If KeyAscii >= 32 Then TxtCellEditor.Text = Chr$(KeyAscii) TxtCellEditor.SelStart = 1 End If End Sub'在TxtCellEditor失去焦点(例如用户单击网格中其他位置)或是Enter,Esc键被按下时,编辑模式结束 Private Sub txtCellEditor_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 13 HideCellEditor Case 27 HideCellEditor True End Select End SubPrivate Sub txtCellEditor_LostFocus() HideCellEditor End SubrecCost对象从数据库中读取数据,HFGCost是MSHFlexGrid对象,因为只读,所以用一个 textbox来模拟修改效果。当修改了 MSHFlexGrid中的数据后,再修改recCost对象中的数据。结果发现除了float型外,其他都没有问题。
Option Explicit Private recCost As New ADODB.Recordset Private logCellRow As Long '记录HFGICost控件的行数 Private logCellCol As Long '记录HFGICost控件列数'将TxtCellEditor控件显示于正确位置 Private Sub ShowCellEditor() With HFGCost .RowSel = .Row .ColSel = .Col TxtCellEditor.Move .Left + .CellLeft, .Top + .CellTop, _ .CellWidth - ScaleX(1, vbPixels, vbTwips), .CellHeight _ - ScaleX(1, vbPixels, vbTwips) TxtCellEditor.Text = .Text TxtCellEditor.SelStart = 0 TxtCellEditor.SelLength = Len(TxtCellEditor.Text) TxtCellEditor.Visible = True TxtCellEditor.ZOrder TxtCellEditor.SetFocus logCellRow = .Row logCellCol = .Col End With End Sub'借助TxtCellEditor控件修改网格控件内的值(TxtCellEditor的编辑功能) Private Sub HideCellEditor(Optional Cancel As Boolean) Dim i As Integer If TxtCellEditor.Visible Then If Not Cancel Then HFGCost.TextMatrix(logCellRow, logCellCol) = TxtCellEditor.Text If recCost.State Then recCost.MoveFirst Dim intTemp As Integer intTemp = logCellRow - 1 Do While intTemp If recCost.State And Not (recCost.EOF) Then recCost.MoveNext intTemp = intTemp - 1 Loop If recCost.State Then recCost.Fields(logCellCol).Value = TxtCellEditor.Text End If TxtCellEditor.Visible = False End If End Sub'双击网格TxtCellEditor编辑功能被激活 Private Sub HFGCost_DblClick() ShowCellEditor End Sub '敲击键盘TxtCellEditor编辑功能被激活 Private Sub HFGCost_KeyPress(KeyAscii As Integer) ShowCellEditor If KeyAscii >= 32 Then TxtCellEditor.Text = Chr$(KeyAscii) TxtCellEditor.SelStart = 1 End If End Sub'在TxtCellEditor失去焦点(例如用户单击网格中其他位置)或是Enter,Esc键被按下时,编辑模式结束 Private Sub txtCellEditor_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 13 HideCellEditor Case 27 HideCellEditor True End Select End SubPrivate Sub txtCellEditor_LostFocus() HideCellEditor End SubrecCost对象从数据库中读取数据,HFGCost是MSHFlexGrid对象,因为只读,所以用一个 textbox来模拟修改效果。当修改了 MSHFlexGrid中的数据后,再修改recCost对象中的数据。结果发现除了float型外,其他都没有问题。
If recCost.State Then recCost.Fields(logCellCol).Value = TxtCellEditor.Text-->> If recCost.State Then recCost.Fields("logCellCol").Value = TxtCellEditor.Text
Private logCellRow As Long '记录HFGICost控件的行数 Private logCellCol As Long '记录HFGICost控件列数logCellCol是一个长整型变量,用来记录HFGCost网格的列索引,而不是字段名!
但是除了float型的字段外,其他字段直接赋值都是没有问题的,如果间接修改的话会复杂的很多。
除了float型的字段外,其他字段都是可以直接赋值的。如果间接修改的话,会复杂的很多。
除了float型的字段外,其他字段都是可以直接赋值的。如果间接修改的话,会复杂的很多。
If recCost.State Then recCost.Fields(logCellCol).Value = Format(TxtCellEditor.Text,"#0.00")
你的问题有点怪,你的数据库设计是否有问题,在库表中给相关字段设置默认值如0、‘’,不允许空等,还有你的recCost的当前状态是否已是最后行,因为你调用了recCost.MoveNext 近intTemp 次。 看我下面的代码,不管memorst.Fields(jj)字段是什么类型,不照样用ddd.Text进行赋值,且整个进销存中的数据录入、修改等都调用下面的方法啊! Public Sub get_text(fmname As Form) Dim jj As Integer For jj = 0 To memorst.Fields.Count - 1 For Each ddd In fmname.Controls If (TypeOf ddd Is TextBox) Or (TypeOf ddd Is ComboBox) Then If ddd.Tag = jj + 100 Then memorst.Fields(jj).value = RTrim(ddd.Text) End If End If Next Next end sub... With memorst Select Case editmode Case "edit" On Error GoTo errorhandle0 get_text fm .Update If dg_refresh Then Call fm.set_dg End If MsgBox "记录已被成功保存", vbOKOnly, "提示" Case "delete" .............
用val()和csng()函数不行
你看看cDbl()或Ccur()看看!
If recCost.State Then recCost.Fields("logCellCol").Value = Val
(TxtCellEditor.Text)如果还是不行,你用用
cDbl()、Ccur()、cLng()再试试看。
Private recCost As New ADODB.Recordset
Private logCellRow As Long '记录HFGICost控件的行数
Private logCellCol As Long '记录HFGICost控件列数'将TxtCellEditor控件显示于正确位置
Private Sub ShowCellEditor()
With HFGCost
.RowSel = .Row
.ColSel = .Col
TxtCellEditor.Move .Left + .CellLeft, .Top + .CellTop, _
.CellWidth - ScaleX(1, vbPixels, vbTwips), .CellHeight _
- ScaleX(1, vbPixels, vbTwips)
TxtCellEditor.Text = .Text
TxtCellEditor.SelStart = 0
TxtCellEditor.SelLength = Len(TxtCellEditor.Text)
TxtCellEditor.Visible = True
TxtCellEditor.ZOrder
TxtCellEditor.SetFocus
logCellRow = .Row
logCellCol = .Col
End With
End Sub'借助TxtCellEditor控件修改网格控件内的值(TxtCellEditor的编辑功能)
Private Sub HideCellEditor(Optional Cancel As Boolean)
Dim i As Integer
If TxtCellEditor.Visible Then
If Not Cancel Then
HFGCost.TextMatrix(logCellRow, logCellCol) = TxtCellEditor.Text
If recCost.State Then recCost.MoveFirst
Dim intTemp As Integer
intTemp = logCellRow - 1
Do While intTemp
If recCost.State And Not (recCost.EOF) Then recCost.MoveNext
intTemp = intTemp - 1
Loop
If recCost.State Then recCost.Fields(logCellCol).Value = TxtCellEditor.Text
End If
TxtCellEditor.Visible = False
End If
End Sub'双击网格TxtCellEditor编辑功能被激活
Private Sub HFGCost_DblClick()
ShowCellEditor
End Sub
'敲击键盘TxtCellEditor编辑功能被激活
Private Sub HFGCost_KeyPress(KeyAscii As Integer)
ShowCellEditor
If KeyAscii >= 32 Then
TxtCellEditor.Text = Chr$(KeyAscii)
TxtCellEditor.SelStart = 1
End If
End Sub'在TxtCellEditor失去焦点(例如用户单击网格中其他位置)或是Enter,Esc键被按下时,编辑模式结束
Private Sub txtCellEditor_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 13
HideCellEditor
Case 27
HideCellEditor True
End Select
End SubPrivate Sub txtCellEditor_LostFocus()
HideCellEditor
End SubrecCost对象从数据库中读取数据,HFGCost是MSHFlexGrid对象,因为只读,所以用一个 textbox来模拟修改效果。当修改了 MSHFlexGrid中的数据后,再修改recCost对象中的数据。结果发现除了float型外,其他都没有问题。
Private recCost As New ADODB.Recordset
Private logCellRow As Long '记录HFGICost控件的行数
Private logCellCol As Long '记录HFGICost控件列数'将TxtCellEditor控件显示于正确位置
Private Sub ShowCellEditor()
With HFGCost
.RowSel = .Row
.ColSel = .Col
TxtCellEditor.Move .Left + .CellLeft, .Top + .CellTop, _
.CellWidth - ScaleX(1, vbPixels, vbTwips), .CellHeight _
- ScaleX(1, vbPixels, vbTwips)
TxtCellEditor.Text = .Text
TxtCellEditor.SelStart = 0
TxtCellEditor.SelLength = Len(TxtCellEditor.Text)
TxtCellEditor.Visible = True
TxtCellEditor.ZOrder
TxtCellEditor.SetFocus
logCellRow = .Row
logCellCol = .Col
End With
End Sub'借助TxtCellEditor控件修改网格控件内的值(TxtCellEditor的编辑功能)
Private Sub HideCellEditor(Optional Cancel As Boolean)
Dim i As Integer
If TxtCellEditor.Visible Then
If Not Cancel Then
HFGCost.TextMatrix(logCellRow, logCellCol) = TxtCellEditor.Text
If recCost.State Then recCost.MoveFirst
Dim intTemp As Integer
intTemp = logCellRow - 1
Do While intTemp
If recCost.State And Not (recCost.EOF) Then recCost.MoveNext
intTemp = intTemp - 1
Loop
If recCost.State Then recCost.Fields(logCellCol).Value = TxtCellEditor.Text
End If
TxtCellEditor.Visible = False
End If
End Sub'双击网格TxtCellEditor编辑功能被激活
Private Sub HFGCost_DblClick()
ShowCellEditor
End Sub
'敲击键盘TxtCellEditor编辑功能被激活
Private Sub HFGCost_KeyPress(KeyAscii As Integer)
ShowCellEditor
If KeyAscii >= 32 Then
TxtCellEditor.Text = Chr$(KeyAscii)
TxtCellEditor.SelStart = 1
End If
End Sub'在TxtCellEditor失去焦点(例如用户单击网格中其他位置)或是Enter,Esc键被按下时,编辑模式结束
Private Sub txtCellEditor_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 13
HideCellEditor
Case 27
HideCellEditor True
End Select
End SubPrivate Sub txtCellEditor_LostFocus()
HideCellEditor
End SubrecCost对象从数据库中读取数据,HFGCost是MSHFlexGrid对象,因为只读,所以用一个 textbox来模拟修改效果。当修改了 MSHFlexGrid中的数据后,再修改recCost对象中的数据。结果发现除了float型外,其他都没有问题。
If recCost.State Then recCost.Fields("logCellCol").Value = TxtCellEditor.Text
Private logCellCol As Long '记录HFGICost控件列数logCellCol是一个长整型变量,用来记录HFGCost网格的列索引,而不是字段名!
看我下面的代码,不管memorst.Fields(jj)字段是什么类型,不照样用ddd.Text进行赋值,且整个进销存中的数据录入、修改等都调用下面的方法啊!
Public Sub get_text(fmname As Form)
Dim jj As Integer
For jj = 0 To memorst.Fields.Count - 1
For Each ddd In fmname.Controls
If (TypeOf ddd Is TextBox) Or (TypeOf ddd Is ComboBox) Then
If ddd.Tag = jj + 100 Then
memorst.Fields(jj).value = RTrim(ddd.Text)
End If
End If
Next
Next
end sub...
With memorst
Select Case editmode
Case "edit"
On Error GoTo errorhandle0
get_text fm
.Update
If dg_refresh Then
Call fm.set_dg
End If
MsgBox "记录已被成功保存", vbOKOnly, "提示"
Case "delete"
.............