Checking if txtbox is null and DCount parameter

R

Rob W

Greetings,

I have the following code assigned to previous record navigation button (See
below) :-

How do I use the Is not null ??
Testing the code the Me.txtAwardId is populated but during the DCount
execution I get the error "The expression you entered as a query parameter
produced the error: 'StrAward'

Can anyone assist? Thanks


VBA code attached to button.

DoCmd.RunCommand acCmdRecordsGoToPrevious

Dim SAwards As Integer
Dim StrAward As String

'IsNotNull (Forms![frmCreateAward]!txtAwardId

StrAward = Me.txtAwardId

SAwards = DCount("[StudentID]", "tblStudent", "[AwardId] = StrAward")
Me.lblAwardStudentCount.Caption = "Total number of Awards enrolled on
the Award is : " & SAwards

'End If

Me.lblRecordNumber.Caption = "Award Record number: " & [CurrentRecord]
 
B

BruceM

The syntax for the DCount criteria is:
DCount("[StudentID]", "tblStudent", "[AwardId] = " " " & StrAward & " " " ")
or
DCount("[StudentID]", "tblStudent", "[AwardId] = ' " & StrAward & " ' ")
Note that the sapeces between the quote marks are for clarity here, and are
not included in the actual expression.

If you are trying to test first to see if txtAwardID is not null:

If Not IsNull(Me.txtAwardID) Then
strAward = Me.txtAwardId
SAwards = DCount("[StudentID]", "tblStudent", "[AwardId] = """ &
StrAward & """")
Me.lblAwardStudentCount.Caption = "Total rewards: " & SAwards
End If

Some lines of your code seem to have an apostrophe in front, which causes
the line of code to be ignored. I don't know if it is a typo or what, but
since I see it I am making the comment.
 
R

Rob W

Thanks for the feedback will now act upon it.

Oh yes, I was aware I was commenting code out, purpose was to test other
lines of code bypassing the syntax errors in the others.

Thanks again.
Rob

BruceM said:
The syntax for the DCount criteria is:
DCount("[StudentID]", "tblStudent", "[AwardId] = " " " & StrAward & " " "
")
or
DCount("[StudentID]", "tblStudent", "[AwardId] = ' " & StrAward & " ' ")
Note that the sapeces between the quote marks are for clarity here, and
are not included in the actual expression.

If you are trying to test first to see if txtAwardID is not null:

If Not IsNull(Me.txtAwardID) Then
strAward = Me.txtAwardId
SAwards = DCount("[StudentID]", "tblStudent", "[AwardId] = """ &
StrAward & """")
Me.lblAwardStudentCount.Caption = "Total rewards: " & SAwards
End If

Some lines of your code seem to have an apostrophe in front, which causes
the line of code to be ignored. I don't know if it is a typo or what, but
since I see it I am making the comment.

Rob W said:
Greetings,

I have the following code assigned to previous record navigation button
(See below) :-

How do I use the Is not null ??
Testing the code the Me.txtAwardId is populated but during the DCount
execution I get the error "The expression you entered as a query
parameter produced the error: 'StrAward'

Can anyone assist? Thanks


VBA code attached to button.

DoCmd.RunCommand acCmdRecordsGoToPrevious

Dim SAwards As Integer
Dim StrAward As String

'IsNotNull (Forms![frmCreateAward]!txtAwardId

StrAward = Me.txtAwardId

SAwards = DCount("[StudentID]", "tblStudent", "[AwardId] = StrAward")
Me.lblAwardStudentCount.Caption = "Total number of Awards enrolled on
the Award is : " & SAwards

'End If

Me.lblRecordNumber.Caption = "Award Record number: " & [CurrentRecord]
 
R

Rob W

Thanks for the advice, all code runs without errors.

Rob W said:
Thanks for the feedback will now act upon it.

Oh yes, I was aware I was commenting code out, purpose was to test other
lines of code bypassing the syntax errors in the others.

Thanks again.
Rob

BruceM said:
The syntax for the DCount criteria is:
DCount("[StudentID]", "tblStudent", "[AwardId] = " " " & StrAward & " " "
")
or
DCount("[StudentID]", "tblStudent", "[AwardId] = ' " & StrAward & " ' ")
Note that the sapeces between the quote marks are for clarity here, and
are not included in the actual expression.

If you are trying to test first to see if txtAwardID is not null:

If Not IsNull(Me.txtAwardID) Then
strAward = Me.txtAwardId
SAwards = DCount("[StudentID]", "tblStudent", "[AwardId] = """ &
StrAward & """")
Me.lblAwardStudentCount.Caption = "Total rewards: " & SAwards
End If

Some lines of your code seem to have an apostrophe in front, which causes
the line of code to be ignored. I don't know if it is a typo or what,
but since I see it I am making the comment.

Rob W said:
Greetings,

I have the following code assigned to previous record navigation button
(See below) :-

How do I use the Is not null ??
Testing the code the Me.txtAwardId is populated but during the DCount
execution I get the error "The expression you entered as a query
parameter produced the error: 'StrAward'

Can anyone assist? Thanks


VBA code attached to button.

DoCmd.RunCommand acCmdRecordsGoToPrevious

Dim SAwards As Integer
Dim StrAward As String

'IsNotNull (Forms![frmCreateAward]!txtAwardId

StrAward = Me.txtAwardId

SAwards = DCount("[StudentID]", "tblStudent", "[AwardId] = StrAward")
Me.lblAwardStudentCount.Caption = "Total number of Awards enrolled on
the Award is : " & SAwards

'End If

Me.lblRecordNumber.Caption = "Award Record number: " & [CurrentRecord]
 
Top