Visual Basic Code for option groups and Combo box

G

Guest

I am trying to create a form where you can selet from an option group and
then narrow down your selection with a combo box to gererate a report. I
have copied a string of text from another form. But I can't seam to get it
to work. Can some let me know what the varsortby value means?

Dim stDocName As String
Dim varhowsort As Variant
Dim vardate As Variant
Dim vardateto As Variant



varsortby = Me!Frame108
vardate = Me!Combo1
vardateto = Me!Combo6
varfm = Me!Combo2

stDocName = "WRAbyDate"

If varsortby = 1 And vardate = "" And vardateto = "" And varfm = "" Then
DoCmd.OpenReport stDocName, acViewPreview
 
G

Guest

The varsortby is a variable that get the value from the Frame108 in the form
which is probably the option group.
From your code I can't see where it has been declared, so if it gives you an
error, just declare it :
Dim varsortby
 
G

Guest

When you mean to declare you are talking about the value set in each option.
I have them set up with a value of 1 - 5. But I am not see in the string
where the varsortby is directed to go to the value.
 
G

Guest

When I say declare I mean
Dim varsortby as ...

You probably didnt provide us with all the code, but I still need to know if
you got an error message.
 
G

Guest

I did not get a error message. The report did not open. Here is the whole
code;

Private Sub Command25_Click()

Dim stDocName As String
Dim varhowsort As Variant
Dim vardate As Variant
Dim vardateto As Variant



varsortby = Me!Frame108
vardate = Me!Combo1
vardateto = Me!Combo6
varfm = Me!Combo2

stDocName = "WRAbyDate"

If varsortby = 1 And vardate = "" And vardateto = "" And varfm = "" Then
DoCmd.OpenReport stDocName, acViewPreview

End If

End Sub
 
G

Guest

In that case try this

If varsortby = 1 And (vardate = "" Or isnull(vardate)) And (vardateto = ""
Or isnull(vardateto)) And (varfm = "" or isnull(varfm)) Then
DoCmd.OpenReport stDocName, acViewPreview
 
G

George Nicholson

But I am not see in the string where the varsortby is directed to go to the

"If varsortby = 1..." begins to address that, but only goes so far. You
probably want to incorporate a Select Case logic structure like:

Dim varsortby as Integer
...........
varsortby = Me!Frame108
...........
Select Case varsortby
Case 1
If vardate = "" And vardateto = "" And varfm = "" Then
DoCmd.OpenReport stDocName, acViewPreview
Else
' do something else?
End If
Case 2
' do something
Case 3
' do something
Case 4
' do something
Case 5
' do something
Case Else
MsgBox "This shouldn't happen"
End Select
 

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

Similar Threads


Top