coding a command button

  • Thread starter Thread starter Chuck216
  • Start date Start date
C

Chuck216

I want to add code to a command button to check for an entry in a table
“tblDownTime†for the current date in the field “date†and for a specific
ride in the field “ride†‘which I want to hard code’ if found then check if
the field “safety†is null. If it is not null then I want it to create an
entry and fill in the date time and reason fields, if the field “safety†is
null then do nothing. I hope this make sense.

Any help with this will be greatly appreciated.
Chuck
 
Perhaps something like the following.

If DCount("*","tblDownTime","DateValue([DateField])=Date() AND [Ride] = 'Some
Value' AND [Safety] is not Null") > 0 then
'Do nothing
ELSE
'Do stuff
Me.DateField = Now()
Me.Reason = "Non Sequitor"
END IF

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
John

Thank you

I think most of that will work. But I want to create a new record in
"tblDownTime" not on a form so the "me." will not work and I'm not very good
at coding so I don't know the code to create a new record it the table.

Chuck

John Spencer said:
Perhaps something like the following.

If DCount("*","tblDownTime","DateValue([DateField])=Date() AND [Ride] = 'Some
Value' AND [Safety] is not Null") > 0 then
'Do nothing
ELSE
'Do stuff
Me.DateField = Now()
Me.Reason = "Non Sequitor"
END IF

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
I want to add code to a command button to check for an entry in a table
“tblDownTime†for the current date in the field “date†and for a specific
ride in the field “ride†‘which I want to hard code’ if found then check if
the field “safety†is null. If it is not null then I want it to create an
entry and fill in the date time and reason fields, if the field “safety†is
null then do nothing. I hope this make sense.

Any help with this will be greatly appreciated.
Chuck
 
Is the form bound to tblDownTime? If so, substitute DateField and Reason
with the actual names of the fields. If not, how come?

Chuck216 said:
John

Thank you

I think most of that will work. But I want to create a new record in
"tblDownTime" not on a form so the "me." will not work and I'm not very
good
at coding so I don't know the code to create a new record it the table.

Chuck

John Spencer said:
Perhaps something like the following.

If DCount("*","tblDownTime","DateValue([DateField])=Date() AND [Ride] =
'Some
Value' AND [Safety] is not Null") > 0 then
'Do nothing
ELSE
'Do stuff
Me.DateField = Now()
Me.Reason = "Non Sequitor"
END IF

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
I want to add code to a command button to check for an entry in a table
“tblDownTime†for the current date in the field “date†and for a
specific
ride in the field “ride†‘which I want to hard code’ if found then
check if
the field “safety†is null. If it is not null then I want it to create
an
entry and fill in the date time and reason fields, if the field
“safety†is
null then do nothing. I hope this make sense.

Any help with this will be greatly appreciated.
Chuck
 
You can try the following. It will add a new record to the table. It won't
show the record to you or go to the record.


Dim strSQL as string
If DCount("*","tblDownTime","DateValue([DateField])=Date() AND [Ride] = 'Some
Value' AND [Safety] is not Null") > 0 then
'Do nothing
ELSE
'Do stuff
strSQL = "INSERT INTO tblDownTime(DateField,Reason) Values(#" & Now() & "#, '"
& "The Reason is" & ")"

Currentdb().Execute StrSQL, dbfailOnError

END IF


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
John

Thank you

I think most of that will work. But I want to create a new record in
"tblDownTime" not on a form so the "me." will not work and I'm not very good
at coding so I don't know the code to create a new record it the table.

Chuck

John Spencer said:
Perhaps something like the following.

If DCount("*","tblDownTime","DateValue([DateField])=Date() AND [Ride] = 'Some
Value' AND [Safety] is not Null") > 0 then
'Do nothing
ELSE
'Do stuff
Me.DateField = Now()
Me.Reason = "Non Sequitor"
END IF

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
I want to add code to a command button to check for an entry in a table
“tblDownTime†for the current date in the field “date†and for a specific
ride in the field “ride†‘which I want to hard code’ if found then check if
the field “safety†is null. If it is not null then I want it to create an
entry and fill in the date time and reason fields, if the field “safety†is
null then do nothing. I hope this make sense.

Any help with this will be greatly appreciated.
Chuck
 
Back
Top