Stamping a field in a table from a form

D

Dave

When I send "frmOrders" to print (print preview), I want to stamp a field
"LastOrderDate" in the table "refCustomers" with the field "OrderDate" in
the current form ("frmOrders")

Current code on the button that sends to print

Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim stDocName As String

stDocName = "Order Invoice"
DoCmd.OpenReport stDocName, acPreview

'DoCmd.Close acForm, "frmOrders", acSaveYes

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

Any pointers?

Thanks in advance
 
C

Carl Rapson

Dave said:
When I send "frmOrders" to print (print preview), I want to stamp a field
"LastOrderDate" in the table "refCustomers" with the field "OrderDate" in
the current form ("frmOrders")

Current code on the button that sends to print

Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim stDocName As String

stDocName = "Order Invoice"
DoCmd.OpenReport stDocName, acPreview

'DoCmd.Close acForm, "frmOrders", acSaveYes

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

Any pointers?

Thanks in advance

How about:

DoCmd.RunSQL "UPDATE [refCustomers] SET [LastOrderDate]=#" & Me.OrderDate &
"#"

right after your OpenReport call.

Carl Rapson
 
D

Dave

Thanks for the reply.

I put in your code but it is all red VBA did not like it as is.
I am assuming I need to replace the "#"'s with something?

Dave

Carl Rapson said:
Dave said:
When I send "frmOrders" to print (print preview), I want to stamp a field
"LastOrderDate" in the table "refCustomers" with the field "OrderDate" in
the current form ("frmOrders")

Current code on the button that sends to print

Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim stDocName As String

stDocName = "Order Invoice"
DoCmd.OpenReport stDocName, acPreview

'DoCmd.Close acForm, "frmOrders", acSaveYes

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

Any pointers?

Thanks in advance

How about:

DoCmd.RunSQL "UPDATE [refCustomers] SET [LastOrderDate]=#" & Me.OrderDate
& "#"

right after your OpenReport call.

Carl Rapson
 
D

Dave

My Bad
I pasted your code in wrong - on 2 lines.
# signs I assume are to enclose a date

NEway - still does not work - Failes and sends me to that line in the code

Dave
Dave said:
Thanks for the reply.

I put in your code but it is all red VBA did not like it as is.
I am assuming I need to replace the "#"'s with something?

Dave

Carl Rapson said:
Dave said:
When I send "frmOrders" to print (print preview), I want to stamp a
field "LastOrderDate" in the table "refCustomers" with the field
"OrderDate" in the current form ("frmOrders")

Current code on the button that sends to print

Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
Dim stDocName As String

stDocName = "Order Invoice"
DoCmd.OpenReport stDocName, acPreview

'DoCmd.Close acForm, "frmOrders", acSaveYes

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

Any pointers?

Thanks in advance

How about:

DoCmd.RunSQL "UPDATE [refCustomers] SET [LastOrderDate]=#" & Me.OrderDate
& "#"

right after your OpenReport call.

Carl Rapson
 
D

Dave

OK - I got it to work but only to find it updates ALL the records in that
table with that date.
I need to update that field for one Record (Customer)

Dave
Carl Rapson said:
Dave said:
When I send "frmOrders" to print (print preview), I want to stamp a field
"LastOrderDate" in the table "refCustomers" with the field "OrderDate" in
the current form ("frmOrders")

Current code on the button that sends to print

Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim stDocName As String

stDocName = "Order Invoice"
DoCmd.OpenReport stDocName, acPreview

'DoCmd.Close acForm, "frmOrders", acSaveYes

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

Any pointers?

Thanks in advance

How about:

DoCmd.RunSQL "UPDATE [refCustomers] SET [LastOrderDate]=#" & Me.OrderDate
& "#"

right after your OpenReport call.

Carl Rapson
 
D

Dave

OK - I got it to work only to find out it stamped the date in ALL records.
I only want to stamp the date for one record - That customer.
I can pass the CustomerID to this code but do not know how I would impliment
it with your update code.

Thanks
Dave
Carl Rapson said:
Dave said:
When I send "frmOrders" to print (print preview), I want to stamp a field
"LastOrderDate" in the table "refCustomers" with the field "OrderDate" in
the current form ("frmOrders")

Current code on the button that sends to print

Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim stDocName As String

stDocName = "Order Invoice"
DoCmd.OpenReport stDocName, acPreview

'DoCmd.Close acForm, "frmOrders", acSaveYes

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

Any pointers?

Thanks in advance

How about:

DoCmd.RunSQL "UPDATE [refCustomers] SET [LastOrderDate]=#" & Me.OrderDate
& "#"

right after your OpenReport call.

Carl Rapson
 
C

Carl Rapson

Try this:

DoCmd.RunSQL "UPDATE [refCustomers] SET [LastOrderDate]=#" & Me.OrderDate &
"# WHERE [CustomerID]=" & Me.CustomerID

Again, all on one line.

Carl Rapson

Dave said:
OK - I got it to work only to find out it stamped the date in ALL records.
I only want to stamp the date for one record - That customer.
I can pass the CustomerID to this code but do not know how I would
impliment it with your update code.

Thanks
Dave
Carl Rapson said:
Dave said:
When I send "frmOrders" to print (print preview), I want to stamp a
field "LastOrderDate" in the table "refCustomers" with the field
"OrderDate" in the current form ("frmOrders")

Current code on the button that sends to print

Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
Dim stDocName As String

stDocName = "Order Invoice"
DoCmd.OpenReport stDocName, acPreview

'DoCmd.Close acForm, "frmOrders", acSaveYes

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

Any pointers?

Thanks in advance

How about:

DoCmd.RunSQL "UPDATE [refCustomers] SET [LastOrderDate]=#" & Me.OrderDate
& "#"

right after your OpenReport call.

Carl Rapson
 
D

Dave

I got it working now.
Thaks again

Dave
Carl Rapson said:
Try this:

DoCmd.RunSQL "UPDATE [refCustomers] SET [LastOrderDate]=#" & Me.OrderDate
& "# WHERE [CustomerID]=" & Me.CustomerID

Again, all on one line.

Carl Rapson

Dave said:
OK - I got it to work only to find out it stamped the date in ALL
records.
I only want to stamp the date for one record - That customer.
I can pass the CustomerID to this code but do not know how I would
impliment it with your update code.

Thanks
Dave
Carl Rapson said:
When I send "frmOrders" to print (print preview), I want to stamp a
field "LastOrderDate" in the table "refCustomers" with the field
"OrderDate" in the current form ("frmOrders")

Current code on the button that sends to print

Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
Dim stDocName As String

stDocName = "Order Invoice"
DoCmd.OpenReport stDocName, acPreview

'DoCmd.Close acForm, "frmOrders", acSaveYes

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

Any pointers?

Thanks in advance


How about:

DoCmd.RunSQL "UPDATE [refCustomers] SET [LastOrderDate]=#" &
Me.OrderDate & "#"

right after your OpenReport call.

Carl Rapson
 

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