Add record if it doesn't already exist

mdbBound

Registered User.
Local time
Today, 06:32
Joined
Dec 8, 2003
Messages
43
Urgent Please help! If Not IsNull(Dlookup...

My goal is to findout if the record exist, open a form message, else, add the record.

Please check my code. it always go on error when it reaches line 9. So from line 9 to line 19, does not work. Please urgent!!!

Error message is "The expression you entered as a query parameter produced this error: 'The object does not have the automation object' WS002."

1 Private Sub cmdReserveWS_Click()
2 On Error GoTo Err_cmdReserveWS_Click
3
4 Dim MainfrmWS As String 'declare variable
5
6 MainfrmWS = Forms![TestMyDMax1]![txtIAssignWS] 'set
7 variable value to your textbox
8
9 If Not IsNull(DLookup("[Rectype]", "testWSLog", "[Rectype]10 = " & MainfrmWS)) Then
11 DoCmd.OpenForm "cfMsgJVExist", acNormal, "", ,
12 acNormal
13 DoCmd.Close acForm, "TestMYDmax1"
14 Else
15 Rectype = MainfrmWS
16 DoCmd.DoMenuItem acFormBar, acRecordsMenu,
17 acSaveRecord, , acMenuVer70
18 DoCmd.Close acForm, "TestMYDmax1"
19 End If
20 Exit_cmdReserveWS_Click:
21 Exit Sub

Err_cmdReserveWS_Click:
MsgBox Err.Description
Resume Exit_cmdReserveWS_Click
End Sub


Thanks.
 
Instead of Dlookup, try a DCount() and test if the record count = 0 [then it does not exist].
 
ghudson said:
Instead of Dlookup, try a DCount() and test if the record count = 0 [then it does not exist].

Im just so in a hurry right now, but can you please rewrite the part I need to change to Dcount

thanks
 
mdbBound said:
1 Private Sub cmdReserveWS_Click()
2 On Error GoTo Err_cmdReserveWS_Click
3
4 Dim MainfrmWS As String 'declare variable
5
6 MainfrmWS = Forms![TestMyDMax1]![txtIAssignWS] 'set
7 variable value to your textbox
8
9 If Not IsNull(DLookup("[Rectype]", "testWSLog", "[Rectype]10 = " & MainfrmWS)) Then
11 DoCmd.OpenForm "cfMsgJVExist", acNormal, "", ,
12 acNormal
13 DoCmd.Close acForm, "TestMYDmax1"
14 Else
15 Rectype = MainfrmWS
16 DoCmd.DoMenuItem acFormBar, acRecordsMenu,
17 acSaveRecord, , acMenuVer70
18 DoCmd.Close acForm, "TestMYDmax1"
19 End If
20 Exit_cmdReserveWS_Click:
21 Exit Sub

Err_cmdReserveWS_Click:
MsgBox Err.Description
Resume Exit_cmdReserveWS_Click
End Sub

Is there something wrong with the [CODE] [/CODE] tags? :confused:
 
what can you say about this Mile?

I need help on this Please.
 
mdbBound said:
Im just so in a hurry right now, but can you please rewrite the part I need to change to Dcount

thanks
You have got to be kidding me! :p

mdbBound said:
what can you say about this Mile?

I need help on this Please.
I would say that you are confused. ;)
 
Well, to the two of you.

I came to this forum for help. Isn't that what this forum is for? Go back to your Mission, Vision, Values, Goals and Objectives and recall why this site was created.

Confused?
People who are not confused will not be so desperate that they spend valueable time to type and describe their problems the best way they can and post their code just to give the full picture of what is happening no matter how wrong it is. I was a little embarass to post my code but what can I do, I thought it will help you, Access Gurus, help me. Sorry, I came to ask for help! If you do not appreciate or welcome my questions just say you can't help me.

ghudson, when I request you to rewrite the DCount, that is only one line. After my meeting is over, I was able to look it up in the book. Some help from this forum.
And Mile, you call yourself a moderator, from where I come from moderators help clear things out in a professional manner.

There are quite few people I want to express my greatest gratitude to: Pat Hartman, The DocMan, Kevin, WayneRyan, Adam Fleck, DALeffler, Kodo, Calvin, OldsoftBoss, PBaldy, Len Brooman and Mike Angelastro. These top of the line quality experts are very professional and have given profound knowledge everyone can build upon.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom