How to update code to alter more than 1 record?

C

Curtis Stevens

I got:
Form A – points to customers table
Form B – points to merchants table

B is in A and I have a command in B with the following code:
Me.MerchantDOB = IIf(Format(Me.MerchantDOB, "mm/dd") <= Format(Date,
"mm/dd"), CDate(Year(Date) + 1 & "/" & Month(Me.MerchantDOB) & "/" &
Day(Me.MerchantDOB)), CDate(Year(Date) & "/" & Month(Me.MerchantDOB) & "/" &
Day(Me.MerchantDOB)))

It works, which I have the form tied to the same table that A uses using the
main key, customerID, what I link all my tables together with.

The problem is if I have more than ONE record in that Merchant table that is
associated with the same customerID in customer’s table, it doesn't change
both, just the first one. Like if you have two owners in a business (what
the merchant table is all about)

What do I need to change in the code to fix it?

Thanks
Curtis
 
C

Curtis Stevens

Nevermind, I found a way around it, created a text box with its data source
using the count expression and then used if that text box is greater than 1,
pop up a msg box telling me to update it manually. Not the same as
automated, but works & doubt what I was wanting was possible anyways...
 
P

Piet Linden

I got:
Form A – points to customers table
Form B – points to merchants table

B is in A and I have a command in B with the following code:
Me.MerchantDOB = IIf(Format(Me.MerchantDOB, "mm/dd") <= Format(Date,
"mm/dd"), CDate(Year(Date) + 1 & "/" & Month(Me.MerchantDOB) & "/" &
Day(Me.MerchantDOB)), CDate(Year(Date) & "/" & Month(Me.MerchantDOB) & "/" &
Day(Me.MerchantDOB)))

It works, which I have the form tied to the same table that A uses using the
main key, customerID, what I link all my tables together with.

The problem is if I have more than ONE record in that Merchant table thatis
associated with the same customerID in customer’s table, it doesn't change
both, just the first one.  Like if you have two owners in a business (what
the merchant table is all about)

What do I need to change in the code to fix it?

Thanks
Curtis

Curtis,
you could use an update query and pass the customerID to your
query....

UPDATE MyTable SET SomeDateField = Forms!MyForm!MyDateControl
WHERE MyTable.CustomerID=Forms!MyForm!MyCustomerIDControl;

If you built this using a string...
strSQL = "UPDATE MyTable SET SomeDateField = #" & Me.Controls
("MyDateControl") & "# WHERE MyTable.CustomerID =" & Me.Controls
("MyCustomerIDControl") & ";"

then you could execute it like this...
DBEngine(0)(0).Execute strSQL
 

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

Top