Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

give focus to textbox in report 2

Status
Not open for further replies.

Duane8889

Programmer
Dec 14, 2001
46
0
0
US
Hello
I'm trying to pull a report from a form and have a textbox in the report have focus. I'm using this code in a click event...
Code:
Reports!rptRotationTwoDay!txtDate2.SetFocus
but I'm getting the error"MS Access doesn't allow you to use this method in the current view.

Any ideas?

thanks Duane
 
There is no way to set the focus to a control on a report. I can't imagine any reason you would want to.

If you told us why, we might be able to recommend a solution.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Hi!

It sounds like you are using the .Text property to set values in the text box. Use the .Value property instead.

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Hello
to Jebry - I'm not sure how to distinguish the difference between the two, text vs. value.

to dhookom - I want to call a report from a form. The report is basically split into two with the day of the week as the header to each side. It is a rotation schedule for work with each column a time slot and the rows are equipment sets. That may be a little vague but when pulling the report on Fridays I need a msgbox to come up and ask the question are you working Saturday. If not, then there needs to be Friday on one side and Monday for the other. If they are working Saturday then it needs to have Friday and Saturday you get the idea.

I am using textboxes for the day of the week. Maybe a label would be better.

the code in the form is...
Code:
Private Sub cmdReportTwoDay_Click()
On Error GoTo Err_cmdReportTwoDay
   Dim stLinkCriteria As String
   stDocName = "rptRotationTwoDay"
   DoCmd.OpenReport stDocName, acPreview

   Reports("rptRotationTwoDay").ZoomControl = 0
   Reports!rptRotationTwoDay!txtDate2.SetFocus

Exit_cmdReportTwoDay_Click:
   Exit Sub

Err_cmdReportTwoDay_Click:
   MsgBox Err.Description
   Resume Exit_cmdReportTwoDay_Click
EndSub
the code in the report is...
Code:
Private Sub Report_Activate()
   DoCmd.Maximize
   Dim myDate As String
   Dim response As Long
   Dim varDate as String

   myDate = Weekday(Date)
   If myDate = 6 Then
     response = MsgBox("It's Friday! Are you working tomorrow?", vbYesNo)
     If response = vbYes Then
       varDate = Format(DateAdd("d", 1, Date), "dddd")
       txtDate2.Text = varDate
     Else
       Reports!rptRotationTwoDay!txtDate2 = Format(DateAdd("d", 3, Date), "dddd")
     End If
   End If
Ens Sub
I may have some reduntant code since in the textbox on the left side of the report I already have code to give the current day of the week. So I could make this an If Then not an If Then Else. There may be a typo or two since I am not at the PC that the program is in.

thanks for any help!
Have a great weekend

Duane
 
First of all, I would never write code in a form that does anything with a report other than open it. Once it's open, the report should function on its own.

I would place a hidden text box on the form and prompt the user if they are working on Saturday and place the proper date in the hidden text box.
Code:
Private Sub cmdReportTwoDay_Click()
On Error GoTo Err_cmdReportTwoDay
   Dim stLinkCriteria As String
   stDocName = "rptRotationTwoDay"
   If WeekDay(Date)=6 Then
      If Msgbox("Are you working tomorrow?",vbYesNo) = vbYes Then
         Me.txtDate = Date +1
        Else
         Me.txtDate = Date + 3
      End If
    Else
      Me.txtDate = Date + 1
   End If
   DoCmd.OpenReport stDocName, acPreview
Exit_cmdReportTwoDay_Click:
   Exit Sub

Err_cmdReportTwoDay_Click:
   MsgBox Err.Description
   Resume Exit_cmdReportTwoDay_Click
EndSub
Then set the control source of txtDate2 on the report to:
=Forms!frmYourForm!txtDate

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Thanks for the suggestion
I tried it and one problem I may be running into is I try to leave the txtDate text box blank and it disappears entirely from the form. It doesn’t go invisible it goes away. So, I try to give it a value such as =Format(Date), “dddd”) in the Control Source and it Errors with “You can’t assign a value to this object”.

I wanted to have it visible at first just to better see what’s going on.
 
Leave which text box blank? If you are referring to txtDate on your form, it should have one or another date regardless.

If you want to assign a value to a control with code, you must leave its control source property empty.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Yes, I had the txtDate blank to be able to put the date in it with code. There now the textbox doesn't go away and has the current date in it. Good! So, it pulls up the report but the txtDate2 in the report is blank.

I have a textbox on the report called txtDate2 referencing txtDate from the form as you suggested with
Code:
=[Forms]![frmRotation]![txtDate]
I had it like this as you suggested but Access changed it.
Code:
=Forms!frmYourForm!txtDate
I believe it's the equivalent of your code

but the txtDate2 in the report is blank.
Getting closer thanks for the help!
 
Why would the textbox have "the current date in it"? The text box should have either 1 or 3 days from the current date.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
It's working now. I took your original suggestion and put the code under report instead of the form.

thanks for all your help and patience!
Duane
 
Hi dhookom

"If you want to assign a value to a control with code, you must leave its control source property empty. "

What if I want to store the content of the textbox into a table? Wouldn't I need to set a control source?

Thanks.
 
Potatohead123,
Do you want to store the value from a report control into a table? I can't imagine a scenario that you would want to do this.

Reports are not meant for pushing values to tables. They should be used for displaying records, calculations,...

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
dhookom,

I'm sorry I wasn't more clear. Actually, I found out what my problem was at work today. Sorry for the inconvenience. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top