Hi all,
I've worked out one of my other problems almost to completion - I've created the following code which creates records of all combinations of listboxes chosen on a form:
However, I'm encountering problems when either cboHostingID or txtRevShare is left blank - I was getting "invalid use of null" to start with, so I tried using IsNull as above and now I get violation errors when Access tries to write the record - I know it's to do with the actual values that are trying to be written (or in this case, not written) to the fields in question. How do I get around this?
For example, the in the tblPartnersets table, HostingID can be empty, but if I try to write nothing to it (i.e. having an unfilled combobox) then I get errors.
I've worked out one of my other problems almost to completion - I've created the following code which creates records of all combinations of listboxes chosen on a form:
Code:
Private Sub cmdSave_Click()
'DoCmd.SetWarnings (0)
Dim Sql As String
Dim PName As String
Dim Channel As Integer
Dim Country As Integer
Dim HostingID As Integer
Dim RevShare As Double
If IsNull(cboPName.Value) Then
MsgBox "Partner name cannot be left blank"
Exit Sub
Else
PName = Chr(34) & cboPName.Value & Chr(34)
End If
If IsNull(cboHostingID.Value) Then
HostingID = 0
Else
HostingID = cboHostingID.Value
End If
If IsNull(txtRevShare.Value) Then
RevShare = 0
Else
RevShare = txtRevShare.Value
End If
For y = 1 To lstChannel.ListCount
If lstChannel.Selected(y) = True Then
Channel = lstChannel.Column(0, y)
Else
Exit For
End If
For x = 0 To lstCountry.ListCount - 1
If lstCountry.Selected(x) = True Then
Country = lstCountry.Column(0, x)
Sql = "INSERT INTO tblPartnersets ([Partner name], ChannelID, CountryID, HostingID, [Revenue share]) Values (" & PName & ", " & Channel & ", " & Country & ", " & HostingID & ", " & RevShare & ");"
Debug.Print Sql
DoCmd.RunSQL Sql
End If
Next x
Next y
DoCmd.SetWarnings (-1)
End Sub
However, I'm encountering problems when either cboHostingID or txtRevShare is left blank - I was getting "invalid use of null" to start with, so I tried using IsNull as above and now I get violation errors when Access tries to write the record - I know it's to do with the actual values that are trying to be written (or in this case, not written) to the fields in question. How do I get around this?
For example, the in the tblPartnersets table, HostingID can be empty, but if I try to write nothing to it (i.e. having an unfilled combobox) then I get errors.