那个大哥帮帮我   我vb程序中有点小问题   在我的程序中新建套帐是不能再列表中立即显示新建的套帐  这个里面不能用刷新来实现   我该怎么解决  我的程序如下:
Private Sub Add_Click()
If cnn.State = 1 Then cnn.Close
cnn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=yxsell;Data Source=."
Set yx1 = cnn.Execute("select * from 用户 where 用户名='" & yxadmin & "'")
If yx1.Fields("权限") <> 1 Then
   msg = MsgBox("您没有用户管理的权限", vbCritical, "斯凯麒ERP—用户管理")
   Exit Sub
   Else
   Newdatabase.Show 1, Me
End If
End Sub

解决方案 »

  1.   

    http://C:\Documents and Settings\Administrator\桌面\斯凯麒ERP
      

  2.   

    就是在菜单中新建的 立即在list—data中能看到新建的套帐
      

  3.   

    'Dim YongHu As New Recordset
    Dim msg As String
    Private aDo_DataBase As New ADODB.Recordset
    Private Sub Add_Click()
    If cnn.State = 1 Then cnn.Close
    cnn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=yxsell;Data Source=."
    Set yx1 = cnn.Execute("select * from 用户 where 用户名='" & yxadmin & "'")
    If yx1.Fields("权限") <> 1 Then
       msg = MsgBox("您没有用户管理的权限", vbCritical, "斯凯麒ERP—用户管理")
       Exit Sub
       Else
       Newdatabase.Show 1, Me
    End If
    End SubPrivate Sub Caiwu_Click()
    If List_data.ListItems.Count <= 0 Then MsgBox "请选中一个套帐!  ", 16: Exit Sub
         msg = MsgBox("你是否要进入编号为(" & List_data.SelectedItem.Text & ")的套帐?", vbOKCancel, "斯凯麒ERP—用户管理")
        If msg = 2 Then Exit Sub
        
          sqlname = List_data.SelectedItem.Text
          
    If cnn.State = 1 Then cnn.Close   '判断用户的权限
    cnn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=yxsell;Data Source=."
    Set yx1 = cnn.Execute("select * from 用户 where 用户名='" & yxadmin & "'")
    If yx1.Fields("权限") = 1 Or yx1.Fields("权限") = 6 Or yx1.Fields("权限") = 7 Then
       CWGuanli.Show 1, Me
       Else
       msg = MsgBox("您没有财务管理的权限", vbCritical, "斯凯麒ERP—用户管理")
       Exit Sub
    End If
    End SubPrivate Sub Delete_Click()If cnn.State = 1 Then cnn.Close
    cnn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=yxsell;Data Source=."
    Set yx1 = cnn.Execute("select * from 用户 where 用户名='" & yxadmin & "'")
    If yx1.Fields("权限") <> 1 Then
       msg = MsgBox("您没有用户管理的权限", vbCritical, "斯凯麒ERP—用户管理")
       Exit Sub
    End IfIf List_data.ListItems.Count <= 0 Then MsgBox "请选中一个套帐!  ", 16: Exit Sub
         msg = MsgBox("你是否要删除编号为(" & List_data.SelectedItem.Text & ")的套帐?", vbOKCancel, "斯凯麒ERP—用户管理")
        If msg = 2 Then Exit Sub
        On Error GoTo Exit_err
            'Class.StatusBar "正在删除套帐信息...", False
            'Me.MousePointer = 12
            cnn.Execute "Drop Database " & List_data.SelectedItem.Key
            cnn.Close
            cnn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=yxsell;Data Source=."
            cnn.Execute "delete 套帐 where 套帐名='" & List_data.SelectedItem.Key & "'"
            Form_Load
            'cnn.Execute "Drop Database 2009111118205"
            'Conn_System.Execute "delete HDSystem_DataBases where DataBasesName='" & DatabaseName & "'"
           ' Form_Load
           ' Class.StatusBar "", True
           ' Me.MousePointer = 0
            Exit Sub
            
           
        
    Exit_err:
        Form_Load
        'Class.StatusBar "", True
       ' Me.MousePointer = 0
        MsgBox Err.Description & "(" & Err.Number & ")", 16End SubPrivate Sub Exit_Click()
    Dim frm     As Form
        
        
              '   在窗体集合中循环
              '   从内存中卸载所有的窗体
              For Each frm In Forms
                      Unload frm                         '     卸载窗体
                      Set frm = Nothing             '   从内存中删除窗体
              NextEnd SubPrivate Sub Form_Load()
        On Error Resume Next
        Dim aDo_DataBase As New Recordset
        
        If cnn.State = 1 Then cnn.Close
        cnn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=yxsell;Data Source=."
        
        Set aDo_DataBase = cnn.Execute("select * from 套帐")
         List_data.ListItems.Clear
        With aDo_DataBase
        Do While Not .EOF
            Set mitem = List_data.ListItems.Add()
            mitem.Text = !套帐名
            mitem.SmallIcon = "taozhang"
            mitem.Icon = "l"
            mitem.SubItems(1) = !创建时间
            mitem.SubItems(2) = !套帐备注
            'mitem.SubItems(3) = !上次备份时间
            mitem.Key = !套帐名
           
            .MoveNext
        Loop
        .Close
        Set aDo_DataBase = Nothing
        End With
    End SubPrivate Sub Mima_Click()
    If cnn.State = 1 Then cnn.Close
    cnn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=yxsell;Data Source=."
    XiuGaiMima.Show 1, Me
    End SubPrivate Sub ShuaXin_Click()
    Form_Load
    End SubPrivate Sub Tool_ButtonClick(ByVal Button As MSComctlLib.Button)
    Select Case Button.Key
           Case "New"
           Add_Click
           Case "Del"
           Delete_Click
           Case "User"
           UserManager_Click
           Case "Exit"
           Exit_Click
           
    End Select
    End SubPrivate Sub UserManager_Click()
    If cnn.State = 1 Then cnn.Close
    cnn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=yxsell;Data Source=."
    Set yx1 = cnn.Execute("select * from 用户 where 用户名='" & yxadmin & "'")
    If yx1.Fields("权限") <> 1 Then
       msg = MsgBox("您没有用户管理的权限", vbCritical, "斯凯麒ERP—用户管理")
       Exit Sub
       Else
       YHGuanLi.Show 1, Me
    End If
       
    End Sub  Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
                
              Dim NN     As VbMsgBoxResult
                
              NN = MsgBox("您确实想退出吗?", vbYesNo, "系统信息")
                
              If NN = vbNo Then
                      Exit_Click
                      Cancel = 1
                      
              Else
                      '其他代码,如果需要的话
              End If
                
        
      End SubPrivate Sub Xingzheng_Click()
    'On Error GoTo Exit_err
    If List_data.ListItems.Count <= 0 Then MsgBox "请选中一个套帐!  ", 16: Exit Sub
         msg = MsgBox("你是否要进入编号为(" & List_data.SelectedItem.Text & ")的套帐?", vbOKCancel, "斯凯麒ERP—用户管理")
        If msg = 2 Then Exit Sub
        
          sqlname = List_data.SelectedItem.Text
          
    If cnn.State = 1 Then cnn.Close   '判断用户的权限
    cnn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=yxsell;Data Source=."
    Set yx1 = cnn.Execute("select * from 用户 where 用户名='" & yxadmin & "'")
    If yx1.Fields("权限") = 1 Or yx1.Fields("权限") = 2 Or yx1.Fields("权限") = 3 Then
       XZGuanli.Show 1, Me
       Else
       msg = MsgBox("您没有行政管理的权限", vbCritical, "斯凯麒ERP—用户管理")
       Exit Sub
    End If
         
           
        
    'Exit_err:
       ' form_load
        'Class.StatusBar "", True
       ' Me.MousePointer = 0
       ' MsgBox Err.Description & "(" & Err.Number & ")", 16End Sub
      

  4.   

    添加之后
    call form_load
    你的代码有几个问题:
    1.代码比较乱
    2.数据库连接代码你完全可以写一个sub或function放在模块中,用的时候直接call,你看你的连接字串都写了多少次.
    3.把数据写到list中的代码你也可以写一个写成sub或function.用的时候直接CALL,这样有个好处,比如你添加一条记录后,再CALL一下这个函数,就可以刷新了.删除也是一样.同样的代码你就不用写多次了