I have a simple form with 3 fields - a listbox which displays a list of venues from table Venue, a text box with a date picker and a text box which allows the user to insert the event name. I need the listbox value to look at the venue table and select the venue id. I then want to update the event table with this venue id, and the text box values of date and event name. The code I have created is as shown :
Private Sub cmdCreateEvent_Click()
Dim dteDateHeld As Date
Dim strEventName As String
Dim strVenue As String
Dim strSQL As String
'check at least the event name is complete - venue and date may be selected after creating the event - check with Lynette
If Me.txtEventName.Text = "" Then
MsgBox "Please enter the name of the event in order to create this record", vbOKOnly
Exit Sub
End If
'pass textbox fields to variables
dteDateHeld = Me.txtDateHeld.Text
strEventName = Me.txtEventName.Text
If Me.lstVenue.ListIndex = -1 Then 'no venue selected
'create sql string to insert details into table if no venue selected
strSQL = "Insert Into Event (EventName, DateHeld) Values (" & strEventName & "," & dteDateHeld & ")"
Else
'Create sql string to insert details into table if venue has been selected
strVenue = Me.lstVenue.Selected
'strSQL = "Insert Into Event (Venue, EventName, DateHeld)Select from Venue (VenueID) Where VenueName = " & strVenue & " "
End If
'execute the sql code to update the table
CurrentDb.Execute strSQL
'clear fields
Me.txtDateHeld.Text = ""
Me.txtEventName.Text = ""
Me.lstVenue = Null
End Sub
I really need help finishing my SQL strings - and if you happen to spot anything else wrong with my code please feel free to let me know. I'm trying to keep it as simple as possible.