Office中国论坛/Access中国论坛

标题: 根据选择字母的自动编号怎么做啊 [打印本页]

作者: chentony    时间: 2011-11-29 14:07
标题: 根据选择字母的自动编号怎么做啊
正在试着做一个系统,主要是广告类的,其中要求是按广告位的分类进行编号:如高速路广告(类型代码为gs);公交车身广告(类型代码为gj),现在要求按不同类进行编号,如高速路有三块广告位,要编成“gs001”、“gs002”、“gs003”,其它类的同理。我已做了一个表(广告资源编号)作,里面有类型代码、广告编号;另一个表是广告资源信息表(里面有广告位编号),在主窗体中有与子窗体对应的未绑定项目,在选择了主窗体中“广告类型”后,主窗体中的“广告位编号”可以根据“广告类型”的选择自动编号(编号样式如上),但做出来的,始终完法根据字母不同编号,如只能编成“gs001”、“gj002”,而不能象这样“gs001”、“gs002"、gj001”,“gj002”.
作者: chentony    时间: 2011-11-29 14:09
补充:是在Access里面做的
作者: andymark    时间: 2011-11-29 15:11
可以的,可能你的语句中少了按类别分类取值的条件
贴出你的语句
作者: chentony    时间: 2011-11-30 23:35
andymark 发表于 2011-11-29 15:11
可以的,可能你的语句中少了按类别分类取值的条件
贴出你的语句

新手刚学,所以不懂的太多了,麻烦支个招哈,谢谢!

Private Sub 广告类型_AfterUpdate()
On Error GoTo Err_广告类型_Click
Dim myrecordset, mylookup As Variant
Dim number As Variant
'DoCmd.GoToRecord , , acNewRec
'If MsgBox("您确定要新编号吗?选是将编新号,而且不能更改和删除", vbYesNo, "关闭!") = vbNo Then
'End
'End If

mylookup = DLookup("类型代码", "广告资源编号")

If IsNull(mylookup) Then
   Set myrecordset = CurrentDb.OpenRecordset("广告资源编号")
   myrecordset.AddNew
   myrecordset("类型代码") = Me.广告类型.Value
   myrecordset("广告编号") = 1
   myrecordset.Update
   number = 1
'End If

Else
  Set myrecordset = CurrentDb.OpenRecordset("广告资源编号")
  number = myrecordset("广告编号") + 1
  myrecordset.Edit
  myrecordset("广告编号") = number
  myrecordset.Update
'ElseIf Format(mylookup, "yyyy/mm") < Format("广告编号", "yyyy/mm") Then
   'Set myrecordset = CurrentDb.OpenRecordset("广告资源编号")
   'myrecordset.Edit
   'myrecordset("类型代码") = Me.广告类型.Value
   'myrecordset("广告编号") = 1
   'myrecordset.Update
   'number = 1
End If


Me![广告位编号] = Me.广告类型.Value & Format(number, "000")
'Me.广告类型.

Exit_广告类型_Click:
    Exit Sub

Err_广告类型_Click:
    MsgBox Err.Description
    Resume Exit_广告类型_Click


End Sub
作者: chentony    时间: 2011-11-30 23:37
[attach]47499[/attach]
作者: chentony    时间: 2011-11-30 23:41
[attach]47501[/attach][attach]47500[/attach]




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3