Random number generator

  • Thread starter butboris via AccessMonster.com
  • Start date
B

butboris via AccessMonster.com

Thanks to this forum I was able to set up a random number generate that would
automatically create a random number.
The range of random number was based on values set for each course, code that
works is below...
I currently have this on the "After Insert" event of the form

Me.Dirty = False
If [Forms]![CourseLocationDetails]![CourseName] = "4" Then
[MSI] = Int((5 * Rnd) + 1)
Else
If [Forms]![CourseLocationDetails]![CourseName] = "1" Then
[MSI] = Int((12 * Rnd) + 1)
Else
If [Forms]![CourseLocationDetails]![CourseName] = "2" Or "5" Then
[MSI] = Int((16 * Rnd) + 1)
End If
End If
End If

Now im trying to set up that when a certain course,namely CourseName] = "3"
is selected and an option box value is set, the code becomes something like:

Me.Dirty = False
'Dim MSI
If [Forms]![CourseLocationDetails]![CourseName] = "4" Then
[MSI] = Int((5 * Rnd) + 1)
Else
If [Forms]![CourseLocationDetails]![CourseName] = "1" Then
[MSI] = Int((12 * Rnd) + 1)
Else
If [Forms]![CourseLocationDetails]![CourseName] = "2" Or "5" Then
[MSI] = Int((16 * Rnd) + 1)
If [Forms]![CourseLocationDetails]![CourseName] = "3" And Me.CourseOptions =
"1" Then
Me.[MSI] = Int((12 * Rnd) + 1)
If [Forms]![CourseLocationDetails]![CourseName] = "3" And Me.CourseOptions =
"2" Then
Me.[MSI] = Int((5 * Rnd) + 1)
If [Forms]![CourseLocationDetails]![CourseName] = "3" And Me.CourseOptions =
"3" Then
Me.[MSI] = Int((14 * Rnd) + 1)

End If
End If
End If
End If
End If
End If

This code just seems to be creating values to the first option box value ie
values to this code, not to any of the other CourseOption = values.ie
generating on this code:
If [Forms]![CourseLocationDetails]![CourseName] = "3" And Me.CourseOptions =
"1" Then
Me.[MSI] = Int((12 * Rnd) + 1.


Where else could I have this code fire or can anyone see where my code is
wrong?

I have tried this code in the after update event of the option box called
[CourseName]
I have been trying by selecting the course option value first but it appears
that this doesnt actually "insert" a record, I have to insert info into a
text box or select combobox before it "inserts" the record.
I have decompiled several times but still happening
 
B

butboris via AccessMonster.com

Found my problem, all resolved for now
I forgot the Else between my new If questions.
Also place the random generator code in the on click event of my option box...

Thanks to this forum I was able to set up a random number generate that would
automatically create a random number.
The range of random number was based on values set for each course, code that
works is below...
I currently have this on the "After Insert" event of the form

Me.Dirty = False
If [Forms]![CourseLocationDetails]![CourseName] = "4" Then
[MSI] = Int((5 * Rnd) + 1)
Else
If [Forms]![CourseLocationDetails]![CourseName] = "1" Then
[MSI] = Int((12 * Rnd) + 1)
Else
If [Forms]![CourseLocationDetails]![CourseName] = "2" Or "5" Then
[MSI] = Int((16 * Rnd) + 1)
End If
End If
End If

Now im trying to set up that when a certain course,namely CourseName] = "3"
is selected and an option box value is set, the code becomes something like:

Me.Dirty = False
'Dim MSI
If [Forms]![CourseLocationDetails]![CourseName] = "4" Then
[MSI] = Int((5 * Rnd) + 1)
Else
If [Forms]![CourseLocationDetails]![CourseName] = "1" Then
[MSI] = Int((12 * Rnd) + 1)
Else
If [Forms]![CourseLocationDetails]![CourseName] = "2" Or "5" Then
[MSI] = Int((16 * Rnd) + 1)
If [Forms]![CourseLocationDetails]![CourseName] = "3" And Me.CourseOptions =
"1" Then
Me.[MSI] = Int((12 * Rnd) + 1)
If [Forms]![CourseLocationDetails]![CourseName] = "3" And Me.CourseOptions =
"2" Then
Me.[MSI] = Int((5 * Rnd) + 1)
If [Forms]![CourseLocationDetails]![CourseName] = "3" And Me.CourseOptions =
"3" Then
Me.[MSI] = Int((14 * Rnd) + 1)

End If
End If
End If
End If
End If
End If

This code just seems to be creating values to the first option box value ie
values to this code, not to any of the other CourseOption = values.ie
generating on this code:
If [Forms]![CourseLocationDetails]![CourseName] = "3" And Me.CourseOptions =
"1" Then
Me.[MSI] = Int((12 * Rnd) + 1.

Where else could I have this code fire or can anyone see where my code is
wrong?

I have tried this code in the after update event of the option box called
[CourseName]
I have been trying by selecting the course option value first but it appears
that this doesnt actually "insert" a record, I have to insert info into a
text box or select combobox before it "inserts" the record.
I have decompiled several times but still happening
 

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

Top