pls come inside.......
所在版块:求学狮城 发贴时间:2003-03-10 15:04  评分:

用户信息
复制本帖HTML代码
高亮: 今天贴 X 昨天贴 X 前天贴 X 
先做一个access文件,save file as namelist.mdb
在里面做一个table, name as FriendInfo. table 里面设置7个column. name, age, address, handphone, workphone, homephone, numberForEntry....(这里假设你同学有3个号码)。 注意,把name, address设置成text; age, 电话号码都设成 number.
把这个mdb文件save到你的VB文件的文件夹里。
以上部分全部在access里面做好。

接下去在你的project里加一个module. click project-->add module. 然后把以下的codes加在里面,save.

Global CurDB As Database

Sub DbOpen()
Set CurDB = OpenDatabase(IIf(Right(App.Path, 1) = "\", App.Path & "namelist.mdb", App.Path & "\namelist.mdb"))
End Sub
Function Path() As String
Path = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\")
End Function

Sub ErrorHandler(Err%, Module$, Action$)
'Error Handling Routine
Dim FNum
Dim FName
FNum = FreeFile
FName = Path() & App.EXEName & ".err"
Open FName For Append As FNum
Print #FNum, " Date/Time : " & Format(Now, "dd/mm/yyyy hh:nn:ss")
Print #FNum, " Module : " & Module
Print #FNum, " Action : " & Action
Print #FNum, " Err Code : " & Err
Print #FNum, " Err Msg : " & Error(Err)
Print #FNum, " " & String$(76, "-")
Close
MsgBox "System encountered an unexpected error !" _
& "Please contact the Technical Personnel.", vbCritical + vbOKOnly
Screen.MousePointer = vbNormal
End Sub



以上是用来连接你的程序去database namelist.mdb. 以后用dbopen就可以连接了。或者说可以对你的database进行操作了。


下面的部分是用在你的add information的form上的。

假设你的form上有6个textbox, from text1 to text6, users are required to enter values of name, age, address, hp number, workphone number and homephone number into the textboxes.另外做一个combo box, 里面的list加上 “handphone“, “workphone“, “homephone“,另外加一个command button, name it cmdOk.

每次user需要输入所以信息,然后从combo box 里选择一个号码来作为以后在entry里显示的号码。

然后把以下的code粘贴....

Private Sub cmdOk_Click()

Dim Entryvalue As Single
If Combo1.Text = "Handphone" Then
Entryvalue = Val(Text4.Text)
ElseIf Combo1.Text = "Workphone" Then
Entryvalue = Val(Text5.Text)
ElseIf Combo1.Text = "HomePhone" Then
Entryvalue = Val(Text6.Text)
End If

DbOpen
CurDB.Execute ("insert into friendinfo values( '" & Trim(Text1.Text) & "' , " & Val(Text2.Text) & " , '" & Trim(Text3.Text) & "', " & Val(Text4.Text) & " , " & Val(Text5.Text) & ", " & Val(Text6.Text) & ", " & Entryvalue & " )")
Call Form_Load
Text1.SetFocus
Exit Sub

End Sub

Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Combo1.Text = ""
End Sub



另外要加上microsoft SDAO 3.6 object Library, 具体是在project-->references.

如果还不行,告诉我你的油箱,我把完整的project发给你。

.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!

Stray birds of summer come to my window to sing and fly away. And yellow leaves of autumn, which have no songs, flutter and fall there with a sign.
 相关帖子 我要回复↙ ↗回到正文
请教有关VB的问题 十九世纪   (287 bytes , 490reads )
pls come inside....... flybird111   (2783 bytes , 444reads )
多谢~~ 十九世纪   (105 bytes , 224reads )
can help me also? 张倏晟   (24 bytes , 213reads )
pls tell me how to help u:) flybird111   (0 bytes , 189reads )