我做了一个窗体想实现客房登记功能
当按下按钮“登记”时,产生凭证号码产生凭证号码的主体代码如下:
Data1.RecordSource = "select * from djb order by 凭证号码"
Data1.Refresh
If Not Data1.Recordset.EOF Then Data1.Recordset.MoveLast
If lsph.Text = "" Then bh.Text = Date & "d" & Format(1, "###000")
If lsph.Text <> "" Then
y1.Text = Month(Date)
y2.Text = Month(Left(lsph.Text, 10))
If y1.Text = y2.Text Then
bh.Text = Date & "d" & Format(Val(Right(lsph.Text, 3)) + 1, "###000")
End If
If y1.Text <> y2.Text Then
bh.Text = Date & "d" & Format(1, "###000")
End If
End If其中lsph是textbox控件,它的datafield为“凭证号码” datasource为Data1
bh也是textbox控件,它在窗体中显示凭证号
运行时出现报错,跳出实时错误‘13’类型不匹配,光标停在y2.Text = Month(Left(lsph.Text, 10))。
有谁能告诉我哪里出错了
当按下按钮“登记”时,产生凭证号码产生凭证号码的主体代码如下:
Data1.RecordSource = "select * from djb order by 凭证号码"
Data1.Refresh
If Not Data1.Recordset.EOF Then Data1.Recordset.MoveLast
If lsph.Text = "" Then bh.Text = Date & "d" & Format(1, "###000")
If lsph.Text <> "" Then
y1.Text = Month(Date)
y2.Text = Month(Left(lsph.Text, 10))
If y1.Text = y2.Text Then
bh.Text = Date & "d" & Format(Val(Right(lsph.Text, 3)) + 1, "###000")
End If
If y1.Text <> y2.Text Then
bh.Text = Date & "d" & Format(1, "###000")
End If
End If其中lsph是textbox控件,它的datafield为“凭证号码” datasource为Data1
bh也是textbox控件,它在窗体中显示凭证号
运行时出现报错,跳出实时错误‘13’类型不匹配,光标停在y2.Text = Month(Left(lsph.Text, 10))。
有谁能告诉我哪里出错了
private sub command1_click()
这行的Date是日期型态不能与文字相加,改为
If lsph.Text = "" Then bh.Text = Date$ & "d" & Format(1, "###000") Y1.Text = Month(Date) 改为 Y1.Text = Cstr(Month(Date$))y2.Text = Month(Left(lsph.Text, 10)) 改为 y2.Text = Cstr(Month(Left(lsph.Text, 10)))bh.Text = Date & "d" & Format(Val(Right(lsph.Text, 3)) + 1, "###000")
改为
bh.Text = Date$ & "d" & Cstr(Format(Val(Right(lsph.Text, 3)) + 1, "###000"))bh.Text = Date & "d" & Format(1, "###000")
改为
bh.Text = Date$ & "d" & Cstr(Format(1, "###000"))
Month()函数不接受字符串,你更改为:
Month(CDate(Left(lsph.Text, 10)))
就可以解决问题了。
你举例说一下lsph.Text的内容是什么样子的(这不会是“秘密”吧?),写一个Sub来处理,把有效的信息提取出来,组合成合法的日期格式不就行了吗?
Data1.Refresh
If Not Data1.Recordset.EOF Then Data1.Recordset.MoveLast'***************************************************
If Not IsData(Left(lsph.Text, 10)) Then
If lsph.Text = "" Then
bh.Text = Date & "d" & Format(1, "###000")
Else
MsgBox Left(lsph.Text, 10) & " 不是合法的日期表达式"
Exit Sub
End If
End If
'***************************************************
y1.Text = Month(Date)
y2.Text = Month(Left(lsph.Text, 10))
If y1.Text = y2.Text Then
bh.Text = Date & "d" & Format(Val(Right(lsph.Text, 3)) + 1, "###000")
Else
bh.Text = Date & "d" & Format(1, "###000")
End If
我把值写入数据库全部改成以下格式:
bh.Text = format(Date,"yyyy-mm-dd") & "d" & Format(1, "###000")
数据库中也全改了.