T
trekgoes2malaysia
Hello,
I have created a subroutine in VBA that checks to see if a user's text
entry ( a new sport) already exists in a table (Sport). My problem is
how to refer to a table field in VBA when that table is not already
open. I have included my code below for viewing. Access returns
error messages for my Dmax & Dmin statements as well as my table
reference in my 'if' statement but I can't figure out my problem even
though I followed my reference books instructions. Any help is
appreciated.
Private Sub SaveRec_Click()
On Error GoTo Err_SaveRec_Click
Dim formname As String
Dim newsport As String
Dim minrec As Integer
Dim maxrec As Integer
Dim intcounter As Integer
newsport = Me.txtsport
formname = "frmsport"
minrec = DMin("[Sportid]", "Sport")
maxrec = DMax("[Sportid]", "Sport")
For intcounter = minrec To maxrec
If newsport = Sport.Sport Then
MsgBox "Sport already exists, try another"
Exit Sub
Next
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
DoCmd.Close acForm, formname
End If
Exit_SaveRec_Click:
Exit Sub
Err_SaveRec_Click:
MsgBox Err.Description
Resume Exit_SaveRec_Click
End Sub
Thanks,
Patrick
I have created a subroutine in VBA that checks to see if a user's text
entry ( a new sport) already exists in a table (Sport). My problem is
how to refer to a table field in VBA when that table is not already
open. I have included my code below for viewing. Access returns
error messages for my Dmax & Dmin statements as well as my table
reference in my 'if' statement but I can't figure out my problem even
though I followed my reference books instructions. Any help is
appreciated.
Private Sub SaveRec_Click()
On Error GoTo Err_SaveRec_Click
Dim formname As String
Dim newsport As String
Dim minrec As Integer
Dim maxrec As Integer
Dim intcounter As Integer
newsport = Me.txtsport
formname = "frmsport"
minrec = DMin("[Sportid]", "Sport")
maxrec = DMax("[Sportid]", "Sport")
For intcounter = minrec To maxrec
If newsport = Sport.Sport Then
MsgBox "Sport already exists, try another"
Exit Sub
Next
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
DoCmd.Close acForm, formname
End If
Exit_SaveRec_Click:
Exit Sub
Err_SaveRec_Click:
MsgBox Err.Description
Resume Exit_SaveRec_Click
End Sub
Thanks,
Patrick