Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add new / Save in Access database

Status
Not open for further replies.

Gimly

Programmer
Jan 5, 2003
26
ZA
Hi there,

I want the program to give me a msg if you either enter a duplicate ID or no ID at all.

If i run the program like this it always gives me the MsgBox "ID exits, cannot duplicate", even though i enter a totaly new ID. If i enter no ID it also gives me the same message.

If i enter the parts that is commented out and also change all my rs to rsp it gives me a error msg "No value given for one or more required parameters" all though all the textboxes have info in them.

My DB is an Access database.

If txtOther(0).Text <> &quot;&quot; Then

'Dim rsp as New Recordset
'rsp.Open &quot;Select * from School where ID=&quot; & txtOther(0).Text, cnPass,adOpenKeyset, adLockOptimistic

If rs.RecordCount = 0 Then

rs.AddNew
rs![ID] = txtOther(0).Text
rs![Name] = txtOther(1).Text
rs![Age] = txtOther(2).Text
rs![Salary] = txtOther(3).Text
rs.Update
' rs.Close
Else
MsgBox &quot;ID exits, cannot duplicate&quot;, vbCritical, &quot;Duplication&quot;
End If
Else
MsgBox &quot;Empty field/s found&quot;, vbCritical, &quot;Empty field/s&quot;
End If

Thank you in advance

Regards

Gimly
 
The recordcount property is not always correct or consistent with Access. You will probably need to use a different method to check if the recordset is empty. I like to use.

If rs.BOF and rs.EOF then...

See thread222-465943 for a discussion on this.

Thanks and Good Luck!

zemp
 
Thank you for your reply, I will definately look into it.

Again Thank you.

Gimly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top