Need help with simple VBA.

Rawr

Registered User.
Local time
Yesterday, 17:25
Joined
Jun 27, 2011
Messages
14
Hello,

Let me begin by saying that I am pretty new to access 2007, but I do know a few things...so feel free to dumb things down :)

Currently, I am building a database, and i've run into a problem trying to transfer data from my cascading combo boxes to a table.

Currently, my code to transfer the data is as followed:

rsttblResp.AddNew
rsttblResp!County = Me.cboCounty1.Column(1)
rsttblResp!Code = Me.cboMun1
rsttblResp!Enteredby = [TempVars]![CurrentUserID]
rsttblResp.Update

But my problem is: since the code is repeated 50 times, I see 50 entries in my table even if I only fill out 2 boxes. There are 2 rows with completed data, and 48 rows with just the username.

How do I get it so the name will only be added to the table if there is other data in the cboCounty or cboMun ?

Thank you for your time.
 
A simple if statement should suffice, if i am understanding your problem correctly.

If Not IsNull(yourComboBox.Value) Then
'Execute Some Code Here
End If

*EDIT* just noticed. as a general helpful hint. you should get into the habit of using .value when sending data from a combo box or a list box. There are only a few cases where access and VBA will implicitly realize you are trying to take the value from a multitude of properties associated with the combo box.
 
As sub says:
Code:
If (Nz(Me.cboCounty1.Value,"") <> "") Or (Nz(Me.cboMun1.Value,"") <> "") Then
    rsttblResp.AddNew
    rsttblResp!County = Me.cboCounty1.Column(1)
    rsttblResp!Code = Me.cboMun1.Value
    rsttblResp!Enteredby = [TempVars]![CurrentUserID]
    rsttblResp.Update 
End If
 
I tried both of your solutions with no success. Maybe I am missing something, but I am still experiencing the same problem.
 

Users who are viewing this thread

Back
Top Bottom