设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1678|回复: 8
打印 上一主题 下一主题

用VB创建ACCESS字段怎样设置他的默认值呀?

[复制链接]
跳转到指定楼层
1#
发表于 2002-10-28 18:23:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
欢迎解答,我都问了好长时间了。[em24][em24][em24][em24]
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
 楼主| 发表于 2002-10-29 02:29:00 | 只看该作者
是没有办法了吗?
3#
 楼主| 发表于 2002-11-1 20:40:00 | 只看该作者
神呀救救我呀?

点击这里给我发消息

4#
发表于 2002-11-1 21:16:00 | 只看该作者
在VB引用DAO或ADOX,你想怎么设就怎么设。[em26]
5#
 楼主| 发表于 2002-11-4 22:06:00 | 只看该作者
您的意思是我先用VBA把数据库和表创出来,然后再用DAO将每个字段设为默认值。当我对其中的一些字段赋值后,那些没赋值的字段就为默认值?

点击这里给我发消息

6#
发表于 2002-11-4 23:42:00 | 只看该作者

下面是DAO3.60中帮助中的例程:
Sub DefaultValueX()

    Dim dbsNorthwind As Database
    Dim tdfEmployees As TableDef
    Dim strOldDefault As String
    Dim rstEmployees As Recordset
    Dim strMessage As String
    Dim strCode As String

    Set dbsNorthwind = OpenDatabase("Northwind.mdb")
    Set tdfEmployees = dbsNorthwind.TableDefs!Employees

    ' Store original DefaultValue information and set the
    ' property to a new value.
    strOldDefault = _
        tdfEmployees.Fields!PostalCode.DefaultValue
    tdfEmployees.Fields!PostalCode.DefaultValue = "98052"

    Set rstEmployees = _
        dbsNorthwind.OpenRecordset("Employees", _
        dbOpenDynaset)

    With rstEmployees
        ' Add a new record to the Recordset.
        .AddNew
        !FirstName = "Bruce"
        !LastName = "Oberg"

        ' Get user input. If user enters something, the field
        ' will be filled with that data; otherwise, it will be
        ' filled with the DefaultValue information.
        strMessage = "Enter postal code for " & vbCr & _
            !FirstName & " " & !LastName & ":"
        strCode = DefaultPrompt(strMessage, !PostalCode)
        If strCode <> "" Then !PostalCode = strCode
        .Update

        ' Go to new record and print information.
        .Bookmark = .LastModified
        Debug.Print "  FirstName = " & !FirstName
        Debug.Print "  LastName = " & !LastName
        Debug.Print "  PostalCode = " & !PostalCode

        ' Delete new record because this is a demonstration.
        .Delete
        .Close
    End With

    ' Restore original DefaultValue property because this is a
    ' demonstration.
    tdfEmployees.Fields!PostalCode.DefaultValue = _
        strOldDefault

    dbsNorthwind.Close

End Sub

Function DefaultPrompt(strPrompt As String, _
    fldTemp As Field) As String

    Dim strFullPrompt As String

    ' Ask user for new DefaultValue setting for the specified
    ' Field object.
    strFullPrompt = strPrompt & vbCr & _
        "[Default = " & fldTemp.DefaultValue & _
        ", Cancel - use default]"
    DefaultPrompt = InputBox(strFullPrompt)

End Function


[em26]
[此贴子已经被zhuyiwen于2002-11-4 15:42:03编辑过]

7#
 楼主| 发表于 2002-11-7 02:29:00 | 只看该作者
斑竹你的DAO帮助到哪里可以下载呀?还有这么好的东东。
8#
发表于 2002-11-7 06:13:00 | 只看该作者
晕.就在ACCESS的帮助文件中。很容易找到,不过是英文的,但仔细阅读话,还是能看懂大多数意思.
9#
 楼主| 发表于 2002-11-7 22:21:00 | 只看该作者
晕,梦里寻她千百度,默然回首那物却在自己的机子里
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-13 13:33 , Processed in 0.097914 second(s), 32 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表