coding a command button

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
 
J

John Spencer

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
 
C

Chuck216

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
 
B

BruceM

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
 
J

John Spencer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

VBA Code 6
Error 3163 2
Eh, don't know, "A real challenge" maybe 4
DLookup debacle 4
Display results based on a date range 2
ok 1
checking overlapping data 2
Open second form based on field value in first form 3

Top