A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Modify record



 
 
Thread Tools Display Modes
  #1  
Old December 12th, 2006, 08:50 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 10
Default Modify record

I need to modify a record but before I do that I need to check and see
if the record exist in the table. If it does than I need to modify the
record and if it does not than basically add new record. When I try to
run the code below I get error message for line "x=DCount("*",......"
saying "Type mismatch" can someone please help me fix this code. Also,
if someone can help me finish the "if" statement, it would be really
appreciated.

I am new to access world and really need all the help I can get.


Function RecordTest()

Dim x as string

'CPAData is the table
'Date is a field in the record, Date/ Timei.e. 1/1/2007
'Cleaners is text field, i.e. "One Stop Cleaning"

x = DCount("*", "[CPAData]", "[Date]=#" & Me.[txtDate] & "#" And
[Cleaners] = """ & Me.txtCleaners & """)

if x = 0 then

'add new record at the end of the table

else

'modify the existing record

endif


end function


Thanks in advance for all your help!

  #2  
Old December 12th, 2006, 10:20 PM posted to microsoft.public.access.forms
Damian S
external usenet poster
 
Posts: 741
Default Modify record

Hi,

There is a problem with your dcount line... Try this one:

DCount("*", "[CPAData]", "[Date]=#" & Me.[txtDate] & "# And
[Cleaners] = '" & Me.txtCleaners & "'")

Inside your if, you want to use an insert statement if the record doesn't
exist, and an update statement if it does... like this:

insert into TABLENAME (FIELD1, FIELD2) values (VALUE1, VALUE2)

or

update TABLENAME set FIELD1 = VALUE1, FIELD2 = VALUE2 where IDFIELD = IDNUMBER

Good luck with it!!

Damian.




" wrote:

I need to modify a record but before I do that I need to check and see
if the record exist in the table. If it does than I need to modify the
record and if it does not than basically add new record. When I try to
run the code below I get error message for line "x=DCount("*",......"
saying "Type mismatch" can someone please help me fix this code. Also,
if someone can help me finish the "if" statement, it would be really
appreciated.

I am new to access world and really need all the help I can get.


Function RecordTest()

Dim x as string

'CPAData is the table
'Date is a field in the record, Date/ Timei.e. 1/1/2007
'Cleaners is text field, i.e. "One Stop Cleaning"

x = DCount("*", "[CPAData]", "[Date]=#" & Me.[txtDate] & "#" And
[Cleaners] = """ & Me.txtCleaners & """)

if x = 0 then

'add new record at the end of the table

else

'modify the existing record

endif


end function


Thanks in advance for all your help!


  #3  
Old December 13th, 2006, 07:40 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 10
Default Modify record

thanks man!

Damian S wrote:
Hi,

There is a problem with your dcount line... Try this one:

DCount("*", "[CPAData]", "[Date]=#" & Me.[txtDate] & "# And
[Cleaners] = '" & Me.txtCleaners & "'")

Inside your if, you want to use an insert statement if the record doesn't
exist, and an update statement if it does... like this:

insert into TABLENAME (FIELD1, FIELD2) values (VALUE1, VALUE2)

or

update TABLENAME set FIELD1 = VALUE1, FIELD2 = VALUE2 where IDFIELD = IDNUMBER

Good luck with it!!

Damian.




" wrote:

I need to modify a record but before I do that I need to check and see
if the record exist in the table. If it does than I need to modify the
record and if it does not than basically add new record. When I try to
run the code below I get error message for line "x=DCount("*",......"
saying "Type mismatch" can someone please help me fix this code. Also,
if someone can help me finish the "if" statement, it would be really
appreciated.

I am new to access world and really need all the help I can get.


Function RecordTest()

Dim x as string

'CPAData is the table
'Date is a field in the record, Date/ Timei.e. 1/1/2007
'Cleaners is text field, i.e. "One Stop Cleaning"

x = DCount("*", "[CPAData]", "[Date]=#" & Me.[txtDate] & "#" And
[Cleaners] = """ & Me.txtCleaners & """)

if x = 0 then

'add new record at the end of the table

else

'modify the existing record

endif


end function


Thanks in advance for all your help!



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:51 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.