There are many things that are not my way of programming, but I'll have to let it go......
Here are a couple of things for you to try/changes I would make:
Code:
Option Compare Database '<<-- EVERY module should have these two lines
Option Explicit '<<-- EVERY module should have these two lines
'I would have a prefix indicating these are module level variables.
Dim MCR As String
Dim Artname As String
Dim Ranname As String
Dim Rannum As Integer
Dim amod As Integer
Dim dmmod As Integer
Dim final As Integer
Dim rannum2 As Integer
Dim mname As String
Dim cexp As Integer
Dim SQL As String ' <<-- "SQL" is a reserved word in Access and shouldn't be an object name
Dim p1ac As Integer
Dim p2ac As Integer
Dim p3ac As Integer
Dim pexp As Integer
Dim texp As Integer
Code:
Sub artbutton_Combo(Rannum) ' <<-- why is there an argument??? Rannum is not used...
Dim MinID As Integer
Dim MaxID As Integer
Dim RandomVal As Integer
Dim arttext As String "see below
MinID = DMin("ID", "Gen")
MaxID = DMax("ID", "Gen")
MinID = 2 'common to all
'SELECT CASE instead of IF...End IF
Select Case Ranname
Case "Common Male"
MaxID = 318
Case "Common Female"
MaxID = 345
Case "High Elf"
MaxID = 838
Case "Roman"
MaxID = 847
Case "Gnomish"
MaxID = 933
Case "Location"
MaxID = 959
Case "Eastern"
MaxID = 1225
Case "Dwarven"
MaxID = 1231
Case "Orcish"
MaxID = 1747
Case "Drow M"
MaxID = 1907
Case "Artname"
MaxID = 2047
Case Else
End Select
Randomize
RandomVal = Int((MaxID * Rnd) + MinID)
arttext = getRandomStuff(RandomVal) '<<-- I would not have a variable named the same as a control on a form
Me.arttext = arttext '<<-- I would not have a variable named the same as a control on a form
End Sub
Code:
Public Function getRandomStuff(lookupVal As Integer) As String
Dim rst As DAO.Recordset
Dim sqlStr As String
' "Ranname" is the table column name
sqlStr = "Select Gen." & Ranname & " FROM Gen Where Gen.ID = " & lookupVal
' sqlStr = "Select Gen.Artname FROM Gen Where Gen.ID = " & lookupVal & ""
Set rst = CurrentDb.OpenRecordset(sqlStr)
If rst.BOF And rst.EOF Then
' maybe a message here about no records found
Else
getRandomStuff = rst!Artname
End If
rst.Close
Set rst = Nothing
End Function
------------------------
If you want to post your dB, do a "Compact and Repair", then Zip it. Max Zip file size = 2 mb.