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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading value of Text or Combo box in VB to select different Reports 1

Status
Not open for further replies.

Locoman

Technical User
Sep 25, 2002
38
GB
I am a relative newbie to using the Visual Basic underlying Forms, etc. I am trying to select different reports with a Form which displays various Parts data. In VB I have worked out how to select different reports based on the state of a data type field OK, however I want to add an unbound user selection box on the form (just shows numbers 1-5) to further sub-divide the report choices.

I seem to be unable to read any data in from the unbound "box": I have tried Text, List and Combo box types with no effect. What have I not understood here?





 
Locoman

I can't see any reason why this shouldn't work. Could you post a code sample so we can see whats going on?

Cheers

Clare
 
Hi Clare,

Here is a sample of my code for the button to generate the report. [Field1] determines the report type to print - this is a table field - and this works OK. I tried to include the user selection button [Listsel] within the selection process. Should I have referred to this seperately in another procedure?

Private Sub Command22_Click()
On Error GoTo Err_Command22_Click
Dim RetVal As Boolean

On [Field1] GoTo lev1, lev2, lev3, lev4, lev5, lev6
GoTo levend

lev6:
RetVal = MsgBox("NO STRUCTURE TO DISPLAY - already at lowest level", vbOKOnly)
GoTo levend

lev1:

If [Listsel] = 1 Then
DoCmd.OpenReport "pL0-1", acViewPreview, "L0-1"
End If
If [Listsel] = 2 Then
DoCmd.OpenReport "pL0-2", acViewPreview, "L0-2"
End If
If [Listsel] = 3 Then
DoCmd.OpenReport "pL0-3", acViewPreview, "L0-3"
End If
If [Listsel] = 4 Then
DoCmd.OpenReport "pL0-4", acViewPreview, "L0-4"
End If
If [Listsel] = 5 Then
DoCmd.OpenReport "pL0-5", acViewPreview, "L0-5"
End If
GoTo levend

lev2: etc., etc

Regards,

Brian
 
I think I would probably handle this with Case statements i.e.

Select Case Me![Field 1]
Case 1
Select Case Me![Listsel]
Case 1
Docmd.OpenReport "Report 1"
Case 2
Docmd.OpenReport "Report 2"
End Select
Case 2
etc....


Would this perhaps do the job for you?
 
Thanks for the tip on Case statement; it reminded me to tidy up the code!

The precise solution to my actual problem is less easy to identify. It appears that the lack of function of the text or combo boxes is due to some sort of corruption to the Code entry screen for the Form, assumed due to the multiple edits whilst I was trying things out.

Although I had deleted all the junk that can get left behind with lots of edits, I knew something was wrong when I could not get any new boxes or option buttons to remember mouse clicks or keyboard strokes. Starting the form design again from scratch with a "clean sheet" solved the problem and it worked first time!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top