Line won't run - why??

BigJ

Board Regular
Joined
Sep 23, 2004
Messages
50
Hi all - my first post on the Access forum and I am very rusty. I'm working on our purchase order log written by somebody else a while ago (now left). I want it to email the report to an approver if a PO is raised with a particular cost centre. The single line of code runs fine in isolation when the form is open that supplies the value (Forms!PO_Standard!Combo71.Value Like "[C-FLA]) , but I just can't get it to run within the context of the rest of the macro. It looks like the form should still be open at that point.

This is how it's supposed to work: the user fills out a form (PO_Standard) then hits a button to run the code below. My line is highlighted in bold. As far as I can see, the form should still be open when the line executes, but nothing happens - it's like the line is just skipped over.



Sub doPOInsert()
Dim stDocName As String
Dim response

response = MsgBox("Are you sure all details are correct?", vbYesNo, "Confirm add new purchase order")
If response = 6 Then


Set rstOrders = New ADODB.Recordset
rstOrders.CursorLocation = adUseClient
rstOrders.Open "Select PONUMBER From [PO Database table] order by PONUMBER ", CurrentProject.Connection, adOpenKeyset, adLockOptimistic

If rstOrders.EOF = True Then


Forms!PO_Standard!PONUMBER = 1

Else
rstOrders.MoveLast
Forms!PO_Standard!PONUMBER = rstOrders!PONUMBER + 1
End If

'add new record
DoCmd.GoToRecord , , acNewRec

' get ponumber and open report
rstOrders.Requery
rstOrders.MoveLast
Forms!PO_Standard!PONUMBER = rstOrders!PONUMBER

'sign-off alert
If Forms!PO_Standard!Combo71.Value Like "[C-FLA]*" Then SendMail


'open report
stDocName = "PO Standard Report early"
DoCmd.OpenReport stDocName, acPreview

rstOrders.Close


' close po entry form
DoCmd.Close acForm, "PO_Standard", acSaveNo
End If
End Sub



Any advice very welcome, and thanks in advance

Jackie
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
'sign-off alert
If Forms!PO_Standard!Combo71.Value Like "[C-FLA]*" Then SendMail

If C-FLA is text, use Like "C-FLA*"
[C-FLA] is the notation you would use for a field called C-FLA

Denis
 
Upvote 0
Thanks Denis, got it working now with your help and getting the value from the report, rather than the form.

Thanks for the help

Jackie
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top