G
Guest
I have a form with the recordsource property left blank. The onOpen event
procedure runs a query depending on who the user is. If the query finds no
records, I want to create a new record. I initialize several fields in new
records in a procedure called by the onCurrent event procedure. I have
tried several ways to do this. When I do it the way shown below using the
addnew method, It blows up in the initialization procedure with the error
message 2427 "You entered an expression that has now value".
I also tried to use the Docmd.gotoRecord , , acNewRec instead of the addnew
method. In this case, the error message is on the Docmd line and says "can't
go to the specified record"
Can anyone tell me what I am doing wrong?
My onOpen procedure looks like this:
Private Sub Form_Open(Cancel As Integer)
' change record source filter depending on who the user is
If CurrentUser = "jdouglas" Or CurrentUser = "dcostello" Then
RecordSource = "select * from [purchase requisition] where status in
('S','P','A')"
Else
RecordSource = "select * from [purchase requisition] where submitter =
currentuser"
End If
'if no records meet the criterion, then create a new one
If Me.Recordset.RecordCount = 0 Then
Me.DataEntry = True
Me.Recordset.AddNew
Requery
End If
End Sub
My initialization procedure:
Private Sub set_up_form()
If IsNull(request_date) Or request_date = " " Then request_date = Now
If IsNull(submitter) Then submitter = CurrentUser
If Me.status = " " Or IsNull(Me.status) Then
cmdStatusChange.Caption = "Click here to submit"
ElseIf Me.status = "S" Then
cmdStatusChange.Caption = "waiting for Purchasing Approval"
ElseIf Me.status = "P" Then
cmdStatusChange.Caption = "waiting for Finance Director
Approval"
ElseIf Me.status = "A" Then
cmdStatusChange.Caption = "Approved"
Else: cmdStatusChange.Caption = "error"
End If
End Sub
procedure runs a query depending on who the user is. If the query finds no
records, I want to create a new record. I initialize several fields in new
records in a procedure called by the onCurrent event procedure. I have
tried several ways to do this. When I do it the way shown below using the
addnew method, It blows up in the initialization procedure with the error
message 2427 "You entered an expression that has now value".
I also tried to use the Docmd.gotoRecord , , acNewRec instead of the addnew
method. In this case, the error message is on the Docmd line and says "can't
go to the specified record"
Can anyone tell me what I am doing wrong?
My onOpen procedure looks like this:
Private Sub Form_Open(Cancel As Integer)
' change record source filter depending on who the user is
If CurrentUser = "jdouglas" Or CurrentUser = "dcostello" Then
RecordSource = "select * from [purchase requisition] where status in
('S','P','A')"
Else
RecordSource = "select * from [purchase requisition] where submitter =
currentuser"
End If
'if no records meet the criterion, then create a new one
If Me.Recordset.RecordCount = 0 Then
Me.DataEntry = True
Me.Recordset.AddNew
Requery
End If
End Sub
My initialization procedure:
Private Sub set_up_form()
If IsNull(request_date) Or request_date = " " Then request_date = Now
If IsNull(submitter) Then submitter = CurrentUser
If Me.status = " " Or IsNull(Me.status) Then
cmdStatusChange.Caption = "Click here to submit"
ElseIf Me.status = "S" Then
cmdStatusChange.Caption = "waiting for Purchasing Approval"
ElseIf Me.status = "P" Then
cmdStatusChange.Caption = "waiting for Finance Director
Approval"
ElseIf Me.status = "A" Then
cmdStatusChange.Caption = "Approved"
Else: cmdStatusChange.Caption = "error"
End If
End Sub