⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmdeviceedit.frm

📁 vb与access数据库的操作实例
💻 FRM
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Begin VB.Form FrmDeviceEdit 
   Caption         =   "编辑设备信息"
   ClientHeight    =   3225
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6630
   LinkTopic       =   "Form1"
   ScaleHeight     =   3225
   ScaleWidth      =   6630
   StartUpPosition =   2  '屏幕中心
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   375
      Left            =   3960
      Top             =   120
      Visible         =   0   'False
      Width           =   1815
      _ExtentX        =   3201
      _ExtentY        =   661
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.TextBox txtId 
      Height          =   330
      Left            =   1080
      TabIndex        =   18
      Top             =   120
      Width           =   1575
   End
   Begin VB.CommandButton Cmd_Exit 
      Caption         =   "取 消"
      Height          =   375
      Left            =   3720
      TabIndex        =   12
      Top             =   2760
      Width           =   1215
   End
   Begin VB.CommandButton Cmd_OK 
      Caption         =   "确 定"
      Height          =   375
      Left            =   1680
      TabIndex        =   11
      Top             =   2760
      Width           =   1215
   End
   Begin VB.Frame Frame1 
      Height          =   2175
      Left            =   120
      TabIndex        =   0
      Top             =   480
      Width           =   6375
      Begin MSDataListLib.DataCombo dco_TypeId 
         Height          =   330
         Left            =   960
         TabIndex        =   20
         Top             =   725
         Width           =   1575
         _ExtentX        =   2778
         _ExtentY        =   582
         _Version        =   393216
         Text            =   ""
      End
      Begin VB.ComboBox cob_Unit 
         Height          =   300
         Left            =   4200
         TabIndex        =   16
         Top             =   1180
         Width           =   1935
      End
      Begin VB.TextBox txtCreateDate 
         Height          =   330
         Left            =   960
         TabIndex        =   15
         Top             =   1605
         Width           =   1575
      End
      Begin VB.TextBox txtPrice 
         Height          =   330
         Left            =   4200
         TabIndex        =   14
         Top             =   725
         Width           =   1935
      End
      Begin VB.TextBox txtCount 
         Height          =   330
         Left            =   960
         TabIndex        =   9
         Top             =   1165
         Width           =   1575
      End
      Begin VB.TextBox txtModel 
         Height          =   330
         Left            =   4200
         TabIndex        =   7
         Top             =   285
         Width           =   1935
      End
      Begin VB.TextBox txtUserName 
         Height          =   330
         Left            =   4200
         TabIndex        =   4
         Top             =   1605
         Width           =   1935
      End
      Begin VB.TextBox txtName 
         Height          =   330
         Left            =   960
         TabIndex        =   2
         Top             =   285
         Width           =   1575
      End
      Begin VB.Label Label9 
         AutoSize        =   -1  'True
         Caption         =   "创 建 人"
         Height          =   180
         Left            =   3360
         TabIndex        =   19
         Top             =   1680
         Width           =   720
      End
      Begin VB.Label Label7 
         AutoSize        =   -1  'True
         Caption         =   "设备单价"
         Height          =   180
         Left            =   3360
         TabIndex        =   13
         Top             =   800
         Width           =   720
      End
      Begin VB.Label Label8 
         AutoSize        =   -1  'True
         Caption         =   "分类名称"
         Height          =   180
         Left            =   120
         TabIndex        =   10
         Top             =   800
         Width           =   720
      End
      Begin VB.Label Label6 
         AutoSize        =   -1  'True
         Caption         =   "设备数量"
         Height          =   180
         Left            =   120
         TabIndex        =   8
         Top             =   1240
         Width           =   720
      End
      Begin VB.Label Label5 
         AutoSize        =   -1  'True
         Caption         =   "设备型号"
         Height          =   180
         Left            =   3360
         TabIndex        =   6
         Top             =   360
         Width           =   720
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         Caption         =   "计量单位"
         Height          =   180
         Left            =   3360
         TabIndex        =   5
         Top             =   1240
         Width           =   720
      End
      Begin VB.Label Label2 
         AutoSize        =   -1  'True
         Caption         =   "创建日期"
         Height          =   180
         Left            =   120
         TabIndex        =   3
         Top             =   1680
         Width           =   720
      End
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         Caption         =   "设备名称"
         Height          =   180
         Left            =   120
         TabIndex        =   1
         Top             =   360
         Width           =   720
      End
   End
   Begin VB.Label Label4 
      AutoSize        =   -1  'True
      Caption         =   "设备编号"
      Height          =   180
      Left            =   240
      TabIndex        =   17
      Top             =   195
      Width           =   720
   End
End
Attribute VB_Name = "FrmDeviceEdit"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public Modify As Boolean '插入=false,修改=true
Public OriId As String  '设备编号
Public iFlag As Integer '标记;1-设备;2-配件

Private Sub Cmd_Exit_Click()
  Unload Me
End Sub

Private Sub Cmd_OK_Click()
  '检查用户录入数据的有效性
  If Len(Trim(txtId)) = 0 Then
    MsgBox ("请输入设备编号")
    txtId.SetFocus
    Exit Sub
  End If
  If Len(Trim(txtName)) = 0 Then
    MsgBox "请输入设备名称"
    txtName.SetFocus
    Exit Sub
  End If
  If Len(Trim(txtModel)) = 0 Then
    MsgBox "请输入设备型号"
    txtModel.SetFocus
    Exit Sub
  End If
  If Len(Trim(dco_TypeId.Text)) = 0 Then
    MsgBox "请选择设备分类"
    dco_TypeId.SetFocus
    Exit Sub
  End If
  If Len(Trim(txtPrice)) = 0 Then
    MsgBox "请输入设备单价"
    txtPrice.SetFocus
    Exit Sub
  End If
  If Len(Trim(cob_Unit.Text)) = 0 Then
    MsgBox "请选择计量单位"
    cob_Unit.SetFocus
    Exit Sub
  End If

  '把用户录入的数据赋值到数据库对象变量中
  With MyDevice
    .Id = MakeStr(txtId)
    .Name = MakeStr(txtName)
    .Model = MakeStr(txtModel)
    .Price = Val(txtPrice)
    .DCount = Val(txtCount)
    .TypeId = Val(dco_TypeId.BoundText)
    .Unit = MakeStr(cob_Unit.Text)
    .CreateDate = MakeStr(txtCreateDate)
    .Poster = MakeStr(txtUserName)
    .Flag = iFlag
    .Status = "正常"
    '根据变量Modify的值,决定是插入新数据,还是修改已有的数据
    If Modify = False Then
      '判断此设备编号是否存在
      If .In_DB(Trim(txtId)) = True Then
        MsgBox ("已经存在此设备编号")
        txtId.SetFocus
        Exit Sub
      End If
      .Insert
    Else
      .Update (OriId)
    End If
  End With
  '关闭窗口
  Unload Me
End Sub

Private Sub Form_Load()
  DataRefresh
End Sub
Private Sub DataRefresh()
  Adodc1.ConnectionString = Conn  '设置连接字符串
  Adodc1.RecordSource = "SELECT * FROM Types WHERE TypeId=1"   '选择设备分类
  Adodc1.Refresh
  Set dco_TypeId.RowSource = Adodc1  '绑定数据源
  dco_TypeId.ListField = "TypeName"  '显示列名
  dco_TypeId.BoundColumn = "Id"      '绑定列值
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -