"Set Focus" problem

Montez659

Well-known Member
Joined
May 4, 2005
Messages
918
Ok, the problem is not that I plan on using setfocus at all, but this
Code:
DoCmd.SelectObject acForm, "Metrics Date Range", False

This is in the Report_Open module that I am running. Essentially, in the Open module, it checks to see if the info has been entered correctly and instead of using the default Access msgbox to enter parameters (which many do not understand) it redirects them to a form where they can enter all of the information.

The above should execute, but I am thinking that I am having a problem with the fact that it is executing before the Open module is done executing therefore resulting in the Form not being the one showing, but the current report with no info on it shows.

I have also tried (and prefered to use)
Code:
DoCmd.Close acReport, "Metrics Reporting"
but I am running into an error where it won't execute when print preview is clicked with an error message that standard error trapping won't seem to move past (i.e., On Error Resume Next). Maybe I have the code wrong since it is not in a loop and an easier fix than I think.

Any help is appreciated greatly appreciated!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Montez659

Well-known Member
Joined
May 4, 2005
Messages
918
Ok, I think that my problem was in my error trapping from an earlier part of the code. I ahd an On Error Goto error1001 and an unknown error was causing it to loop down to that portion of my code and try to close an unopen report.

However, I am having an unusual problem where the Report_Open module seems to be running twice, but not sure why. Posted below is all of my code. Even as I step through the code it completely exits the sub, but then starts all over again. Maybe someone can see what is going on.
Code:
Private Sub Report_Open(Cancel As Integer)
Dim begDate As Date
Dim endDate As Date
Dim strSql As String
Dim a

'get dates
'On Error GoTo error1001
begDate = pubBegDate
endDate = pubEndDate

If begDate < "01/01/1900" Or endDate < "01/01/1900" Then
    GoTo error1001
End If

'display dates
lblBegDate.Caption = begDate
lblEndDate.Caption = endDate

Dim w9sRecd, w9sComp, w9sIn14, w9sUnfin As Integer
Dim w9sIn14Pct
Dim tfRecd, tfComp, tfIn14 As Integer
Dim tfIn14Pct

'get W9 counts
On Error Resume Next
w9sRecd = DCount("ID", "Metrics_W9s_General", "")
w9sComp = DCount("[Completed Date]", "Metrics_W9s_General", "")
w9sIn14 = DCount("ID", "Metrics_W9s_14", "")
w9sIn14Pct = FormatPercent(w9sIn14 / w9sRecd)
w9sUnfin = DCount("ID", "Metrics_W9s_Unfinished", "")


'display W9 counts
lblW9Received.Caption = w9sRecd
lblW9sDone.Caption = w9sComp
lblW9s14days.Caption = w9sIn14
lblW9sPct.Caption = w9sIn14Pct
lblW9sUnfinished.Caption = w9sUnfin

'gets tf counts
tfRecd = DCount("ID", "Metrics_TF_General", "")
tfComp = DCount("[Completed Date]", "Metrics_TF_General", "")
tfIn14 = DCount("ID", "Metrics_TF_14", "")
tfIn14Pct = FormatPercent(tfIn14 / tfRecd)

'displays tf counts
lblTFRecd.Caption = tfRecd
lblTFDone.Caption = tfComp
lblTF14days.Caption = tfIn14
lblTFpct.Caption = tfIn14Pct

GoTo endIt
error1001:
a = MsgBox("You cannot generate this report without entering the date ranges. Please do so using the 'Metrics Date Range' form.", vbCritical)
DoCmd.OpenForm "Metrics Date Range"
DoCmd.Close acReport, "Metrics Reporting"
endIt:
End Sub
 
Upvote 0

Montez659

Well-known Member
Joined
May 4, 2005
Messages
918
Alright, well forget that problem. I just made the Report hidden and so they shan't be clicking on it. I took out all of the error trapping and such and it works nicely. They can only begin the process by clicking on the form.
 
Upvote 0

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
I think that might be what I was going to suggest, open the report from the form and not the other way round.

Also, do all the error checking you can in the form before you open the report.
 
Upvote 0

Forum statistics

Threads
1,191,517
Messages
5,987,059
Members
440,074
Latest member
Emmanuelian

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
Top